Class: Kintone::Query

Inherits:
Object show all
Defined in:
lib/kintone/query.rb,
lib/kintone/query/extension.rb

Defined Under Namespace

Modules: Extention Classes: Field

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Query

Returns a new instance of Query.



4
5
6
7
# File 'lib/kintone/query.rb', line 4

def initialize(&block)
  @query = []
  instance_eval(&block) if block_given?
end

Instance Method Details

#and!Object



15
16
17
# File 'lib/kintone/query.rb', line 15

def and!
  @query << 'and'
end

#field(code) ⇒ Object Also known as: f



9
10
11
12
13
# File 'lib/kintone/query.rb', line 9

def field(code)
  condition = Field.new(code)
  @query << condition
  condition
end

#inspectObject



67
68
69
# File 'lib/kintone/query.rb', line 67

def inspect
  to_s
end

#last_monthObject



43
44
45
# File 'lib/kintone/query.rb', line 43

def last_month
  function_string('LAST_MONTH()')
end

#limit(count) ⇒ Object



55
56
57
# File 'lib/kintone/query.rb', line 55

def limit(count)
  @query << "limit #{count}"
end

#login_userObject



27
28
29
# File 'lib/kintone/query.rb', line 27

def 
  function_string('LOGINUSER()')
end

#nowObject



31
32
33
# File 'lib/kintone/query.rb', line 31

def now
  function_string('NOW()')
end

#offset(index) ⇒ Object



59
60
61
# File 'lib/kintone/query.rb', line 59

def offset(index)
  @query << "offset #{index}"
end

#or!Object



19
20
21
# File 'lib/kintone/query.rb', line 19

def or!
  @query << 'or'
end

#order_by(field, sort = :asc) ⇒ Object



51
52
53
# File 'lib/kintone/query.rb', line 51

def order_by(field, sort = :asc)
  @query << "order by #{field} #{sort}"
end

#precede(&block) ⇒ Object



23
24
25
# File 'lib/kintone/query.rb', line 23

def precede(&block)
  @query << "(#{Kintone::Query.new(&block)})" if block_given?
end

#this_monthObject



39
40
41
# File 'lib/kintone/query.rb', line 39

def this_month
  function_string('THIS_MONTH()')
end

#this_yearObject



47
48
49
# File 'lib/kintone/query.rb', line 47

def this_year
  function_string('THIS_YEAR()')
end

#to_sObject



63
64
65
# File 'lib/kintone/query.rb', line 63

def to_s
  @query.map(&:to_s).join(' ')
end

#todayObject



35
36
37
# File 'lib/kintone/query.rb', line 35

def today
  function_string('TODAY()')
end