Class: Dolphin::DataStore::BaseRdb

Inherits:
Object
  • Object
show all
Defined in:
lib/dolphin/data_stores/base_rdb.rb

Direct Known Subclasses

Mysql

Constant Summary collapse

ORM =
Dolphin::Models::Rdb::Orm

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ BaseRdb

Returns a new instance of BaseRdb.



5
6
7
8
9
10
11
12
13
14
# File 'lib/dolphin/data_stores/base_rdb.rb', line 5

def initialize(config)
  @adapter = config[:adapter]
  @host = config[:host]
  @user = config[:user]
  @password = config[:password]
  @database = config[:database]

  # Set timezone to UTC
  Sequel.default_timezone = :utc
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dolphin/data_stores/base_rdb.rb', line 20

def closed?
  @connection.nil?
end

#connect_pathObject



51
52
53
# File 'lib/dolphin/data_stores/base_rdb.rb', line 51

def connect_path
  "#{@adapter}://#{@host}/#{@database}?user=#{@user}&password=#{@password}"
end

#current_databaseObject



16
17
18
# File 'lib/dolphin/data_stores/base_rdb.rb', line 16

def current_database
  Sequel.connect(connect_path)
end

#delete_notification(notification) ⇒ Object



46
47
48
49
# File 'lib/dolphin/data_stores/base_rdb.rb', line 46

def delete_notification(notification)
  n = Dolphin::Models::Rdb::Notification.new(ORM::Notification)
  n.delete(notification)
end

#get_event(params) ⇒ Object



36
37
38
39
# File 'lib/dolphin/data_stores/base_rdb.rb', line 36

def get_event(params)
  e = Dolphin::Models::Rdb::Event.new(ORM::Event)
  e.get(params)
end

#get_notification(id) ⇒ Object



26
27
28
29
# File 'lib/dolphin/data_stores/base_rdb.rb', line 26

def get_notification(id)
  n = Dolphin::Models::Rdb::Notification.new(ORM::Notification)
  n.get(id)
end

#put_event(event) ⇒ Object



31
32
33
34
# File 'lib/dolphin/data_stores/base_rdb.rb', line 31

def put_event(event)
  e = Dolphin::Models::Rdb::Event.new(ORM::Event)
  e.put(event)
end

#put_notification(id, methods) ⇒ Object



41
42
43
44
# File 'lib/dolphin/data_stores/base_rdb.rb', line 41

def put_notification(id, methods)
  n = Dolphin::Models::Rdb::Notification.new(ORM::Notification)
  n.put(id, methods)
end