Class: ROM::RethinkDB::Gateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/rom/rethinkdb/gateway.rb

Instance Method Summary collapse

Constructor Details

#connect(options) ⇒ Gateway

RethinkDB gateway interface

Examples:

gateway = ROM::RethinkDB::Gateway.new({ host: 'localhost',
  port: 28015, db: 'database' })

Connects to database passing options

Parameters:

  • options (Hash)

    connection options



19
20
21
22
23
24
# File 'lib/rom/rethinkdb/gateway.rb', line 19

def initialize(options)
  @datasets = {}
  @options = options
  @rql = ::RethinkDB::RQL.new
  @connection = rql.connect(options)
end

Instance Method Details

#[](name) ⇒ Dataset

Return dataset with the given name

Parameters:

  • name (String)

    dataset name

Returns:



45
46
47
# File 'lib/rom/rethinkdb/gateway.rb', line 45

def [](name)
  datasets[name.to_s]
end

#dataset(name) ⇒ Dataset

Return dataset with the given name

Parameters:

  • name (String)

    a dataset name

Returns:



33
34
35
36
# 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) ⇒ Boolean

Check if dataset exists

Parameters:

  • name (String)

    dataset name

Returns:

  • (Boolean)


54
55
56
57
58
59
# 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

#disconnectObject

Disconnect from database



64
65
66
# File 'lib/rom/rethinkdb/gateway.rb', line 64

def disconnect
  connection.close
end