Class: Rmodel::Sequel::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/rmodel/sequel/source.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, table) ⇒ Source

Returns a new instance of Source.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
# File 'lib/rmodel/sequel/source.rb', line 6

def initialize(connection, table)
  @connection = connection
  raise ArgumentError, 'Connection is not setup' unless @connection

  @table = table
  raise ArgumentError, 'Table can not be guessed' unless @table
end

Instance Method Details

#build_queryObject



30
31
32
# File 'lib/rmodel/sequel/source.rb', line 30

def build_query
  Query.new(@connection[@table])
end

#delete(id) ⇒ Object



26
27
28
# File 'lib/rmodel/sequel/source.rb', line 26

def delete(id)
  @connection[@table].where(id: id).delete
end

#delete_by_query(query) ⇒ Object



38
39
40
# File 'lib/rmodel/sequel/source.rb', line 38

def delete_by_query(query)
  exec_query(query).delete
end

#exec_query(query) ⇒ Object



34
35
36
# File 'lib/rmodel/sequel/source.rb', line 34

def exec_query(query)
  query
end

#find(id) ⇒ Object



14
15
16
# File 'lib/rmodel/sequel/source.rb', line 14

def find(id)
  @connection[@table].where(id: id).first
end

#insert(tuple) ⇒ Object



18
19
20
# File 'lib/rmodel/sequel/source.rb', line 18

def insert(tuple)
  @connection[@table].insert(tuple)
end

#update(id, tuple) ⇒ Object



22
23
24
# File 'lib/rmodel/sequel/source.rb', line 22

def update(id, tuple)
  @connection[@table].where(id: id).update(tuple)
end