#pg_runner
Providing connection pool and easy query tools for postgresql
- libpq-dev
libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.
- official site
- Installation
# at Ubuntu $$ apt-get install libpq-dev
- postgres(pg)
A ruby gem for postgresql
- official site
- Installation
$$ gem install pg
- PG::BasicConnectionPool
A database connection pool for postgresql. Default pool size is 5.
- PG::SingleConnectionPool
A database connection pool supporting only one connection for postgresql. This is a fake connection pool for the transaction function of SqlRunner
- PG::SqlRunner
A simple sql executer class
connection_pool = PG::BasicConnectionPool.new( dbhost, port, dbname, username, password, pool_sise(optional) ) runner = PG::SqlRunner.new( connection_pool )
# query rs = runner.query( "select 1" ) rs.each do | row | # do something end # query with block rs = runner.query( "select * from blabla where $1 = 1" ) do | result | # do something end # query with params rs = runner.query( "select * from blabla where $1 = 1" , [1] ) # query with params & block rs = runner.query( "select * from blabla where $1 = 1" , [1] ) do | result | # do something end
runner.transaction do | runner | # do some transaction works with runner # raise Exception if you want rollback end
# work with PG::Connection runner.connect do | conn | do # bla bla~ end