Class: Jrec::Collection
- Inherits:
-
Object
show all
- Includes:
- PG
- Defined in:
- lib/jrec/collection.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from PG
#config, #config_file, #env, #exec_func, #exec_params, #pg
Constructor Details
#initialize(schema, table) ⇒ Collection
Returns a new instance of Collection.
18
19
20
21
|
# File 'lib/jrec/collection.rb', line 18
def initialize schema, table
self.table = table
self.schema = schema
end
|
Instance Attribute Details
#schema ⇒ Object
Returns the value of attribute schema.
16
17
18
|
# File 'lib/jrec/collection.rb', line 16
def schema
@schema
end
|
#table ⇒ Object
Returns the value of attribute table.
16
17
18
|
# File 'lib/jrec/collection.rb', line 16
def table
@table
end
|
Class Method Details
.[](table) ⇒ Object
12
13
14
|
# File 'lib/jrec/collection.rb', line 12
def self.[]table
self.tables[table] ||= new(:public,table)
end
|
.tables ⇒ Object
8
9
10
|
# File 'lib/jrec/collection.rb', line 8
def self.tables
@@tables ||= {}
end
|
Instance Method Details
#all ⇒ Object
46
47
48
|
# File 'lib/jrec/collection.rb', line 46
def all
where({})
end
|
#count(conds = {}) ⇒ Object
41
42
43
|
# File 'lib/jrec/collection.rb', line 41
def count conds = {}
exec_func :query, schema, table, {select: 'COUNT(id)'}.merge(conds).to_json
end
|
#delete_all ⇒ Object
62
63
64
|
# File 'lib/jrec/collection.rb', line 62
def delete_all
delete({})
end
|
#find(uuid) ⇒ Object
58
59
60
|
# File 'lib/jrec/collection.rb', line 58
def find uuid
find_by(uuid: uuid)
end
|
#find_by(cond) ⇒ Object
54
55
56
|
# File 'lib/jrec/collection.rb', line 54
def find_by cond
query({where: cond,limit: 1})[1..-2]
end
|
#where(cond) ⇒ Object
50
51
52
|
# File 'lib/jrec/collection.rb', line 50
def where cond
query({where: cond})
end
|