class RethinkdbHelper

Constants

DEFAULTS

Public Class Methods

new(options={}) click to toggle source

TODO: Limited to one table per instance, consider

support for multiple table per db support;
consider multiple db per instance support.
# File lib/rethinkdb_helper.rb, line 41
def initialize(options={})
  @options = DEFAULTS.merge(options)

  @connection = connect

  db_drop if db_exist? && drop?

  unless  db_exist?
    if create_if_missing?
      db_create
    else
      raise "db: '#{@options[:db]}' does not exist"
    end
  end

  use(@options[:db])

  unless table_exist?
    if create_if_missing?
      table_create
    else
      raise "table: '#{@options[:table]}' does not exist"
    end
  end

  @table = r.table(@options[:table])
end

Public Instance Methods

add(payloads, options={})
Alias for: insert
between_keys(lower_key, upper_key, options={})
Alias for: get_between_keys
changes(options={}) click to toggle source
# File lib/rethinkdb_helper.rb, line 152
def changes(options={})
  @table.changes(options).run(connect)
end
connect(options={host: @options[:host], port: @options[:port]}) click to toggle source
# File lib/rethinkdb_helper.rb, line 104
def connect(options={host: @options[:host], port: @options[:port]})
  r.connect(options).repl
end
create_db(db_name=@options[:db])
Alias for: db_create
create_if_missing?() click to toggle source
# File lib/rethinkdb_helper.rb, line 211
def create_if_missing?
  @options[:create_if_missing]
end
create_simple_index(field_name) click to toggle source
# File lib/rethinkdb_helper.rb, line 186
def create_simple_index(field_name)
  @table.index_create(field_name.to_s).run
end
create_table(table_name=@options[:table], options={})
Alias for: table_create
db(db_name=@options[:db]) click to toggle source

def use(db_name=@options)

@connection.use(db_name)

end

# File lib/rethinkdb_helper.rb, line 121
def db(db_name=@options[:db])
  @db = r.db(db_name)
end
db_config() click to toggle source
# File lib/rethinkdb_helper.rb, line 91
def db_config
  @db.config.run
end
db_create(db_name=@options[:db]) click to toggle source
# File lib/rethinkdb_helper.rb, line 160
def db_create(db_name=@options[:db])
  @db = r.db_create(db_name).run
end
Also aliased as: create_db
db_delete(db_name=@options[:db])
Alias for: db_drop
db_drop(db_name=@options[:db]) click to toggle source
# File lib/rethinkdb_helper.rb, line 108
def db_drop(db_name=@options[:db])
  @db    = nil
  @table = nil
  r.db_drop(db_name).run
end
Also aliased as: drop_db, db_delete, delete_db
db_exist?(db_name=@options[:db]) click to toggle source
# File lib/rethinkdb_helper.rb, line 156
def db_exist?(db_name=@options[:db])
  db_list.include?(db_name)
end
db_list() click to toggle source
# File lib/rethinkdb_helper.rb, line 165
def db_list
  r.db_list.run
end
Also aliased as: list_db
db_wait(*options) click to toggle source
# File lib/rethinkdb_helper.rb, line 96
def db_wait(*options)
  @db.wait(options).run
end
delete_db(db_name=@options[:db])
Alias for: db_drop
delete_index(index_name)
Alias for: index_drop
drop?() click to toggle source
# File lib/rethinkdb_helper.rb, line 207
def drop?
  @options[:drop]
end
drop_db(db_name=@options[:db])
Alias for: db_drop
drop_inde(index_name)
Alias for: index_drop
drop_table(table_name=@options[:table])
Alias for: table_drop
elete_table(table_name=@options[:table])
Alias for: table_drop
flush()
Alias for: sync
get_all_keys(keys, options={}) click to toggle source
# File lib/rethinkdb_helper.rb, line 219
def get_all_keys(keys, options={})
  @table.get_all([keys].flatten, options).run
end
get_between_keys(lower_key, upper_key, options={}) click to toggle source
# File lib/rethinkdb_helper.rb, line 223
def get_between_keys(lower_key, upper_key, options={})
  @table.between(lower_key, upper_key, options).run
end
Also aliased as: between_keys
get_key(key) click to toggle source
# File lib/rethinkdb_helper.rb, line 215
def get_key(key)
  @table.get(key).run
end
get_table(table_name=@options[:table], options) click to toggle source
# File lib/rethinkdb_helper.rb, line 129
def get_table(table_name=@options[:table], options)
  r.table(table_name, options).run
end
index_delete(index_name)
Alias for: index_drop
index_drop(index_name) click to toggle source
# File lib/rethinkdb_helper.rb, line 195
def index_drop(index_name)
  @table.index_drop(index_name).run
end
Also aliased as: drop_inde, delete_index, index_delete
index_list() click to toggle source
# File lib/rethinkdb_helper.rb, line 190
def index_list
  @table.index_list.run
end
Also aliased as: list_indexes
index_wait(*indexes) click to toggle source
# File lib/rethinkdb_helper.rb, line 179
def index_wait(*indexes)
  @table.index_wait(indexes).run
end
Also aliased as: wait_on_index, wait_for_index, wait_index, wait_on_index
insert(payloads, options={}) click to toggle source

payloads is an array of hashes or a single hash document.

# File lib/rethinkdb_helper.rb, line 236
def insert(payloads, options={})
  payloads = [payloads].flatten
  raise 'No document provided' if payloads.empty?
  invalid_payloads = false
  payloads.map{|doc| invalid_payloads &&= !doc.is_a?(Hash)}
  raise 'Invalid document: must be Hash' if invalid_payloads
  @table.insert(payloads.flatten, options).run
end
Also aliased as: add, load
join(foreign_key, table_name,options={}) click to toggle source
# File lib/rethinkdb_helper.rb, line 229
def join(foreign_key, table_name,options={})
  @table.eq_join(foreign_key,
    r.table(table_name), options).without({:right => "id"}).zip().run
end
list_db()
Alias for: db_list
list_indexes()
Alias for: index_list
list_table()
Alias for: table_list
load(payloads, options={})
Alias for: insert
rebalance() click to toggle source
# File lib/rethinkdb_helper.rb, line 82
def rebalance
  @table.rebalance.run
end
Also aliased as: table_rebalance
reconfigure(options={}) click to toggle source
# File lib/rethinkdb_helper.rb, line 77
def reconfigure(options={})
  @taboe.reconfigure(options).run
end
Also aliased as: table_reconfigure
server_wait(*options) click to toggle source
# File lib/rethinkdb_helper.rb, line 100
def server_wait(*options)
  r.wait(options).run
end
sync() click to toggle source
# File lib/rethinkdb_helper.rb, line 133
def sync
  @table.sync.run
end
Also aliased as: flush
table(table_name=@options[:table],options={}) click to toggle source
# File lib/rethinkdb_helper.rb, line 125
def table(table_name=@options[:table],options={})
  @table = r.table(table_name, options)
end
table_config() click to toggle source
# File lib/rethinkdb_helper.rb, line 87
def table_config
  @table.config.run
end
table_create(table_name=@options[:table], options={}) click to toggle source
# File lib/rethinkdb_helper.rb, line 139
def table_create(table_name=@options[:table], options={})
  @table = r.table_create(table_name, options).run
end
Also aliased as: create_table
table_delete(table_name=@options[:table])
Alias for: table_drop
table_drop(table_name=@options[:table]) click to toggle source
# File lib/rethinkdb_helper.rb, line 144
def table_drop(table_name=@options[:table])
  @table = nil
  @db.table_drop(table_name)
end
Also aliased as: drop_table, elete_table, table_delete
table_exist?(table_name=@options[:table]) click to toggle source
# File lib/rethinkdb_helper.rb, line 175
def table_exist?(table_name=@options[:table])
  table_list.include?(table_name)
end
table_list() click to toggle source
# File lib/rethinkdb_helper.rb, line 170
def table_list
  r.table_list.run
end
Also aliased as: list_table
table_rebalance()
Alias for: rebalance
table_reconfigure(options={})
Alias for: reconfigure
table_status(table_name=@options[:table]) click to toggle source
# File lib/rethinkdb_helper.rb, line 73
def table_status(table_name=@options[:table])
  r.table_status(table_name).run
end
table_wait(*options) click to toggle source
# File lib/rethinkdb_helper.rb, line 69
def table_wait(*options)
  @table.wait(options).run
end
wait_for_index(*indexes)
Alias for: index_wait
wait_index(*indexes)
Alias for: index_wait
wait_on_index(*indexes)
Alias for: index_wait