Class: Database
- Inherits:
-
Object
- Object
- Database
- Defined in:
- lib/dbexpect/database.rb
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(con) ⇒ Database
constructor
A new instance of Database.
- #insert_rows(insert_statements) ⇒ Object
- #num_rows_match(schema, table, query) ⇒ Object
- #truncate_table(schema, name) ⇒ Object
Constructor Details
#initialize(con) ⇒ Database
Returns a new instance of Database.
33 34 35 |
# File 'lib/dbexpect/database.rb', line 33 def initialize(con) @connection = con end |
Class Method Details
.from_connection(con) ⇒ Object
20 21 22 |
# File 'lib/dbexpect/database.rb', line 20 def self.from_connection(con) new(con) end |
.hash_from_config ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/dbexpect/database.rb', line 24 def self.hash_from_config databases = {} YAML.load_file('database.yml').each do |(dsn,config)| databases[dsn.to_sym] = from_connection(OdbcConnection.new(dsn,config)) end databases end |
Instance Method Details
#close ⇒ Object
55 56 57 |
# File 'lib/dbexpect/database.rb', line 55 def close #@connection.close end |
#insert_rows(insert_statements) ⇒ Object
49 50 51 52 53 |
# File 'lib/dbexpect/database.rb', line 49 def insert_rows(insert_statements) insert_statements.each do |stmt| @connection.run(stmt) end end |
#num_rows_match(schema, table, query) ⇒ Object
37 38 39 |
# File 'lib/dbexpect/database.rb', line 37 def num_rows_match(schema,table,query) @connection.run("select * from #{schema}.#{table} where (#{query})").count end |
#truncate_table(schema, name) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/dbexpect/database.rb', line 41 def truncate_table(schema,name) if @connection.type == 'db2' @connection.run("truncate table #{schema}.#{name} immediate") else @connection.run("truncate table #{schema}.#{name}") end end |