Project

dbwrapper

0.0
No commit activity in last 3 years
No release in over 3 years
manipulatie with sqlite3,mysql,postgresql in the same way
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

Dbwrapper

This library manipulate various db(mysql2,sqlite,postgresql) in the same way. you can use query with placeholder. still more, multiple insert with hash array and csv backup and csv restore.

Installation

Add this line to your application's Gemfile:

gem 'dbwrapper'

Add this line if you use sqlite3

gem 'sqlite3'

Add these lines if you use postgresql

gem 'pg'
gem 'pg_typecast'

Add these lines if you use mysql2

gem 'mysql2'
gem 'mysql2-cs-bind'

And then execute:

$ bundle

Or install it yourself as:

#with sqlite3
$ gem install dbwrapper sqlite3

#with postgresql
$ gem install dbwrapper pg pg_typecast

#with mysql2
$ gem install dbwrapper mysql2 mysql2-cs-bind

#or all
$ gem install dbwrapper sqlite3 pg pg_typecast mysql2 mysql2-cs-bind

Usage

#sqlite3
db=Dbwrapper::DB.new(database: "test.sqlite3",adapter: "sqlite3")
#mysql2
db=Dbwrapper::DB.new(database: "test",adapter: "mysql2",username: "root",password: "xxxx")
#postgresql
db=Dbwrapper::DB.new(database: "test",adapter: "postgresql",username: "root",password: "xxxx")

#or merely
db=Dbwrapper::DB.new(YAML::load(File.open('database.yml'))["development"])
#create table depends on db type this example is mysql2. because datetime is paticular mysql.
db.query("create table users (id integer,name text,created_at datetime)")
#insert
db.query('insert users (id,name,created_at) value(?,?,?)',1,"smith","2014-2014-06-26 00:00:00")
#last_id 1
db.last_id
#select return array of hash [{"id"=>1, "name"=>"smith", "created_at"=>2014-06-26 00:00:00 +0900}]
db.query("select * from users")
#update
db.query("update users set name=? where id = ?","hay",1)
#affected_rows 1
db.affected_rows
#multiple insert with hash
db.xinsert("users",[{id: 2,name: "hello",created_at: "2014-2014-06-26 00:00:00"},{id: 3,name: "good",created_at: "2014-2014-06-27 00:00:00"}])
#backup_table tablename,path csv made in /var/backup/users.csv
db.backup_table("users","/var/backup")
#truncate
db.truncate("users")
#restore table
db.restore_table("users","/var/backup")
#close
db.close

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request