Class: Rethinker::Database
- Inherits:
-
Object
- Object
- Rethinker::Database
- Defined in:
- lib/rethinker/database.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(connection) ⇒ Database
constructor
A new instance of Database.
- #purge!(options = {}) ⇒ Object
- #raw ⇒ Object
Constructor Details
#initialize(connection) ⇒ Database
Returns a new instance of Database.
6 7 8 |
# File 'lib/rethinker/database.rb', line 6 def initialize(connection) self.connection = connection end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
2 3 4 |
# File 'lib/rethinker/database.rb', line 2 def connection @connection end |
Class Method Details
.truncate_table!(table_name) ⇒ Object
35 36 37 |
# File 'lib/rethinker/database.rb', line 35 def self.truncate_table!(table_name) Rethinker.run { RethinkDB::RQL.new.table(table_name).delete } end |
Instance Method Details
#purge!(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rethinker/database.rb', line 14 def purge!(={}) if [:drop] connection.db_drop(database_name) else # truncating each table is much faster table_list.each do |table_name| self.class.truncate_table!(table_name) end end rescue RuntimeError => e raise e unless e. =~ /No entry with that name/ end |
#raw ⇒ Object
10 11 12 |
# File 'lib/rethinker/database.rb', line 10 def raw @raw ||= RethinkDB::RQL.new.db(database_name) end |