class Cyby::Kintone::Relation
Attributes
condition[R]
fields[R]
order_by[R]
Public Class Methods
new(app)
click to toggle source
# File lib/cyby/kintone/relation.rb, line 9 def initialize(app) @app = app @condition = Query::Where.new @order_by = [] @fields = nil end
Public Instance Methods
and(cond, *params)
click to toggle source
# File lib/cyby/kintone/relation.rb, line 36 def and(cond, *params) case cond when String @condition = Query::WhereAnd.new(@condition, Query::Where.new(cond, *params)) else @condition = Query::WhereAnd.new(@condition, cond.condition) end self end
asc(field)
click to toggle source
# File lib/cyby/kintone/relation.rb, line 56 def asc(field) @order_by << "#{field} asc" self end
desc(field)
click to toggle source
# File lib/cyby/kintone/relation.rb, line 61 def desc(field) @order_by << "#{field} desc" self end
each() { |record| ... }
click to toggle source
# File lib/cyby/kintone/relation.rb, line 16 def each args = {} args[:query] = to_query args[:fields] = @fields if @fields records = @app.find(args) records.map do |record| yield record end end
inspect()
click to toggle source
# File lib/cyby/kintone/relation.rb, line 79 def inspect { app: @app.id, query: to_query, select: @fields }.inspect end
or(cond, *params)
click to toggle source
# File lib/cyby/kintone/relation.rb, line 46 def or(cond, *params) case cond when String @condition = Query::WhereOr.new(@condition, Query::Where.new(cond, *params)) else @condition = Query::WhereOr.new(@condition, cond.condition) end self end
select(*fields)
click to toggle source
# File lib/cyby/kintone/relation.rb, line 66 def select(*fields) @fields = fields self end
to_query()
click to toggle source
# File lib/cyby/kintone/relation.rb, line 71 def to_query query = @condition.to_query if @order_by.any? query += " order by #{@order_by.join(',')}" end query end
where(cond, *params)
click to toggle source
# File lib/cyby/kintone/relation.rb, line 26 def where(cond, *params) case cond when String @condition = Query::Where.new(cond, *params) else @condition = cond.condition end self end