Module: Arel

Defined in:
lib/arel_extensions/nodes/select.rb,
lib/arel_extensions.rb

Defined Under Namespace

Modules: Nodes Classes: InsertManager, SelectManager, Table

Class Method Summary collapse

Class Method Details

.column_of(table_name, column_name) ⇒ Object



97
98
99
# File 'lib/arel_extensions.rb', line 97

def self.column_of table_name, column_name
  ArelExtensions.column_of(table_name, column_name)
end

.duration(s, expr) ⇒ Object



101
102
103
# File 'lib/arel_extensions.rb', line 101

def self.duration s, expr
  ArelExtensions::Nodes::Duration.new("#{s}i", expr)
end

.falseObject

The FALSE pseudo literal.



106
107
108
# File 'lib/arel_extensions.rb', line 106

def self.false
  Arel::Nodes::Equality.new(1, 0)
end

.grouping(*v) ⇒ Object



110
111
112
# File 'lib/arel_extensions.rb', line 110

def self.grouping *v
  Arel::Nodes::Grouping.new(*v)
end

.json(*expr) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/arel_extensions.rb', line 114

def self.json *expr
  ArelExtensions::Nodes::Json.new(
    if expr.length == 1
      expr.first
    else
      expr
    end
  )
end

.json_falseObject



134
135
136
137
138
139
140
141
142
# File 'lib/arel_extensions.rb', line 134

def self.json_false
  res = Arel.grouping(Arel.quoted('false'))
  res.instance_eval {
    def return_type
      :boolean
    end
  }
  res
end

.json_trueObject



124
125
126
127
128
129
130
131
132
# File 'lib/arel_extensions.rb', line 124

def self.json_true
  res = Arel.grouping(Arel.quoted('true'))
  res.instance_eval {
    def return_type
      :boolean
    end
  }
  res
end

.nullObject

The NULL literal.



145
146
147
# File 'lib/arel_extensions.rb', line 145

def self.null
  Arel.quoted(nil)
end

.quoted(*args) ⇒ Object



149
150
151
# File 'lib/arel_extensions.rb', line 149

def self.quoted *args
  Arel::Nodes.build_quoted(*args)
end

.randObject



153
154
155
# File 'lib/arel_extensions.rb', line 153

def self.rand
  ArelExtensions::Nodes::Rand.new
end

.rollup(*args) ⇒ Object



157
158
159
# File 'lib/arel_extensions.rb', line 157

def self.rollup(*args)
  Arel::Nodes::RollUp.new(args)
end

.shorten(s) ⇒ Object



161
162
163
# File 'lib/arel_extensions.rb', line 161

def self.shorten s
  Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
end

.trueObject

The TRUE pseudo literal.



166
167
168
# File 'lib/arel_extensions.rb', line 166

def self.true
  Arel::Nodes::Equality.new(1, 1)
end

.tuple(*v) ⇒ Object



170
171
172
173
# File 'lib/arel_extensions.rb', line 170

def self.tuple *v
  tmp = Arel.grouping(nil)
  Arel.grouping v.map{|e| tmp.convert_to_node(e)}
end

.when(condition) ⇒ Object

For instance

“‘ Arel.when(at.is_null).then(0).else(1) “`



180
181
182
# File 'lib/arel_extensions.rb', line 180

def self.when condition
  ArelExtensions::Nodes::Case.new.when(condition)
end