Class: ActionBlocks::DatabaseFunctions

Inherits:
Object
  • Object
show all
Defined in:
lib/action_blocks/data_engine/database_functions.rb

Instance Method Summary collapse

Instance Method Details

#count(node, *args) ⇒ Object



16
17
18
19
20
21
# File 'lib/action_blocks/data_engine/database_functions.rb', line 16

def count(node, *args)
  Arel::Nodes::NamedFunction.new(
    'count',
    [node]
  )
end

#every(predicate, value, node, *args) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/action_blocks/data_engine/database_functions.rb', line 30

def every(predicate, value, node, *args)
  every_part = Arel::Nodes::NamedFunction.new(
    'every',
    [node.send(predicate, Arel::Nodes.build_quoted(value))]
  )

  Arel::Nodes::NamedFunction.new('CAST', [every_part.as('TEXT')])
end

#string_agg(delimiter, node, *args) ⇒ Object



23
24
25
26
27
28
# File 'lib/action_blocks/data_engine/database_functions.rb', line 23

def string_agg(delimiter, node, *args)
  Arel::Nodes::NamedFunction.new(
    'string_agg',
    [node, Arel::Nodes.build_quoted(delimiter)]
  )
end

#timezone(tz, node, user, *args) ⇒ Object

methods define their own params, always followed by current node and current user



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/action_blocks/data_engine/database_functions.rb', line 4

def timezone(tz, node, user, *args)
  utc = Arel::Nodes::NamedFunction.new(
    'timezone',
    [Arel::Nodes.build_quoted('UTC'), node]
  )

  Arel::Nodes::NamedFunction.new(
    'timezone',
    [Arel::Nodes.build_quoted(tz), utc]
  )
end