Class: Actn::DB::Set
- Inherits:
-
Object
show all
- Includes:
- PG
- Defined in:
- lib/actn/db/set.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from PG
#db_config, #exec_func, #exec_params, #exec_prepared, #pg
Constructor Details
#initialize(schema = :public, table) ⇒ Set
Returns a new instance of Set.
19
20
21
22
|
# File 'lib/actn/db/set.rb', line 19
def initialize schema = :public, table
self.table = table
self.schema = schema
end
|
Instance Attribute Details
#schema ⇒ Object
Returns the value of attribute schema.
17
18
19
|
# File 'lib/actn/db/set.rb', line 17
def schema
@schema
end
|
#table ⇒ Object
Returns the value of attribute table.
17
18
19
|
# File 'lib/actn/db/set.rb', line 17
def table
@table
end
|
Class Method Details
.[](table) ⇒ Object
13
14
15
|
# File 'lib/actn/db/set.rb', line 13
def self.[]table
self.tables[table] ||= new(table)
end
|
.tables ⇒ Object
9
10
11
|
# File 'lib/actn/db/set.rb', line 9
def self.tables
@@tables ||= {}
end
|
Instance Method Details
#all ⇒ Object
44
45
46
|
# File 'lib/actn/db/set.rb', line 44
def all
where({})
end
|
#count(conds = {}) ⇒ Object
39
40
41
|
# File 'lib/actn/db/set.rb', line 39
def count conds = {}
exec_func :query, schema, table, {select: 'COUNT(id)'}.merge(conds).to_json
end
|
#delete_all ⇒ Object
60
61
62
|
# File 'lib/actn/db/set.rb', line 60
def delete_all
delete({})
end
|
#find(uuid) ⇒ Object
56
57
58
|
# File 'lib/actn/db/set.rb', line 56
def find uuid
find_by(uuid: uuid)
end
|
#find_by(cond) ⇒ Object
52
53
54
|
# File 'lib/actn/db/set.rb', line 52
def find_by cond
query({where: cond,limit: 1})[1..-2]
end
|
#validate_and_upsert(data) ⇒ Object
33
34
35
36
|
# File 'lib/actn/db/set.rb', line 33
def validate_and_upsert data
sql = "SELECT __upsert($1,$2,__validate($3,$4))"
exec_prepared sql.parameterize.underscore, sql, [schema, table, table.classify, data.to_json]
end
|
#where(cond) ⇒ Object
48
49
50
|
# File 'lib/actn/db/set.rb', line 48
def where cond
query({where: cond})
end
|