class ROM::RethinkDB::Gateway
Attributes
datasets[R]
@api private
options[R]
@api private
rql[R]
@api private
Public Class Methods
new(options)
click to toggle source
RethinkDB
gateway interface
@overload connect(options)
Connects to database passing options @param [Hash] options connection options
@example
gateway = ROM::RethinkDB::Gateway.new({ host: 'localhost', port: 28015, db: 'database' })
@api public
# File lib/rom/rethinkdb/gateway.rb, line 19 def initialize(options) @datasets = {} @options = options @rql = ::RethinkDB::RQL.new @connection = rql.connect(options) end
Public Instance Methods
[](name)
click to toggle source
Return dataset with the given name
@param [String] name dataset name
@return [Dataset]
@api public
# File lib/rom/rethinkdb/gateway.rb, line 45 def [](name) datasets[name.to_s] end
dataset(name)
click to toggle source
Return dataset with the given name
@param [String] name a dataset name
@return [Dataset]
@api public
# File lib/rom/rethinkdb/gateway.rb, line 33 def dataset(name) rql.db(options[:db]).table(name.to_s).run(connection) datasets[name] = Dataset.new(rql.table(name.to_s), rql, connection) end
dataset?(name)
click to toggle source
Check if dataset exists
@param [String] name dataset name
@api public
# File lib/rom/rethinkdb/gateway.rb, line 54 def dataset?(name) rql.db(options[:db]).table(name.to_s).run(connection) true rescue ::RethinkDB::RqlRuntimeError false end
disconnect()
click to toggle source
Disconnect from database
@api public
# File lib/rom/rethinkdb/gateway.rb, line 64 def disconnect connection.close end