class Jrec::Collection

Attributes

schema[RW]
table[RW]

Public Class Methods

[](table) click to toggle source
# File lib/jrec/collection.rb, line 12
def self.[]table
  self.tables[table] ||= new(:public,table)
end
new(schema, table) click to toggle source
# File lib/jrec/collection.rb, line 18
def initialize schema, table
  self.table = table
  self.schema = schema
end
tables() click to toggle source
# File lib/jrec/collection.rb, line 8
def self.tables
  @@tables ||= {}
end

Public Instance Methods

all() click to toggle source
# File lib/jrec/collection.rb, line 46
def all
  where({})
end
count(conds = {}) click to toggle source
# 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() click to toggle source
# File lib/jrec/collection.rb, line 62
def delete_all
  delete({})
end
find(uuid) click to toggle source
# File lib/jrec/collection.rb, line 58
def find uuid
  find_by(uuid: uuid)
end
find_by(cond) click to toggle source
# File lib/jrec/collection.rb, line 54
def find_by cond
  query({where: cond,limit: 1})[1..-2]
end
where(cond) click to toggle source
# File lib/jrec/collection.rb, line 50
def where cond
  query({where: cond})        
end