Class: Rethinker::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/rethinker/database.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#connectionObject

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!(options={})
  if options[: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.message =~ /No entry with that name/
end

#rawObject



10
11
12
# File 'lib/rethinker/database.rb', line 10

def raw
  @raw ||= RethinkDB::RQL.new.db(database_name)
end