Class: M4DBI::Database
Instance Method Summary (collapse)
- - (Boolean) connected?
- - (Object) database_name
- - (Object) disconnect
- - (Object) driver
- - (Object) execute(*args) (also: #update, #u, #insert, #i, #delete, #d)
-
- (Database) initialize(rdbi_dbh)
constructor
A new instance of Database.
- - (Object) last_query
- - (Object) prepare(*args)
- - (Object) select(sql, *bindvars) (also: #select_all, #s)
- - (Object) select_column(sql, *bindvars) (also: #sc)
- - (Object) select_one(sql, *bindvars) (also: #s1)
- - (Object) table_schema(*args)
- - (Object) transaction(&block)
Constructor Details
- (Database) initialize(rdbi_dbh)
A new instance of Database
5 6 7 |
# File 'lib/m4dbi/database.rb', line 5 def initialize( rdbi_dbh ) @dbh = rdbi_dbh end |
Instance Method Details
- (Boolean) connected?
45 46 47 |
# File 'lib/m4dbi/database.rb', line 45 def connected? @dbh.connected? end |
- (Object) database_name
57 58 59 |
# File 'lib/m4dbi/database.rb', line 57 def database_name @dbh.database_name end |
- (Object) disconnect
49 50 51 |
# File 'lib/m4dbi/database.rb', line 49 def disconnect @dbh.disconnect end |
- (Object) driver
69 70 71 |
# File 'lib/m4dbi/database.rb', line 69 def driver @dbh.driver end |
- (Object) execute(*args) Also known as: update, u, insert, i, delete, d
13 14 15 |
# File 'lib/m4dbi/database.rb', line 13 def execute( *args ) @dbh.execute *args end |
- (Object) last_query
65 66 67 |
# File 'lib/m4dbi/database.rb', line 65 def last_query @dbh.last_query end |
- (Object) prepare(*args)
9 10 11 |
# File 'lib/m4dbi/database.rb', line 9 def prepare( *args ) Statement.new( @dbh.prepare(*args) ) end |
- (Object) select(sql, *bindvars) Also known as: select_all, s
17 18 19 |
# File 'lib/m4dbi/database.rb', line 17 def select( sql, *bindvars ) execute( sql, *bindvars ).fetch( :all, RDBI::Result::Driver::Struct ) end |
- (Object) select_column(sql, *bindvars) Also known as: sc
25 26 27 28 29 30 31 32 |
# File 'lib/m4dbi/database.rb', line 25 def select_column( sql, *bindvars ) rows = execute( sql, *bindvars ).fetch( 1, RDBI::Result::Driver::Array ) if rows.any? rows[ 0 ][ 0 ] else raise RDBI::Error.new( "Query returned no rows. SQL: #{@dbh.last_query}" ) end end |
- (Object) select_one(sql, *bindvars) Also known as: s1
21 22 23 |
# File 'lib/m4dbi/database.rb', line 21 def select_one( sql, *bindvars ) select( sql, *bindvars )[ 0 ] end |
- (Object) table_schema(*args)
53 54 55 |
# File 'lib/m4dbi/database.rb', line 53 def table_schema( *args ) @dbh.table_schema( *args ) end |
- (Object) transaction(&block)
61 62 63 |
# File 'lib/m4dbi/database.rb', line 61 def transaction( &block ) @dbh.transaction &block end |