abstract class Jennifer::QueryBuilder::Function
- Jennifer::QueryBuilder::Function
- Jennifer::QueryBuilder::Criteria
- Jennifer::QueryBuilder::SQLNode
- Reference
- Object
Overview
Presents SQL function invocation.
Jennifer::Query["users"].where { coalesce(sql("NULL"), _name) == "John" }
# SELECT users. FROM users WHERE COALESCE(NULL, users.name) == "John"
Direct Known Subclasses
- Jennifer::QueryBuilder::AbsFunction
- Jennifer::QueryBuilder::AvgFunction
- Jennifer::QueryBuilder::CeilFunction
- Jennifer::QueryBuilder::CoalesceFunction
- Jennifer::QueryBuilder::ConcatFunction
- Jennifer::QueryBuilder::ConcatWsFunction
- Jennifer::QueryBuilder::CountFunction
- Jennifer::QueryBuilder::CurrentDateFunction
- Jennifer::QueryBuilder::CurrentTimeFunction
- Jennifer::QueryBuilder::CurrentTimestampFunction
- Jennifer::QueryBuilder::FloorFunction
- Jennifer::QueryBuilder::LowerFunction
- Jennifer::QueryBuilder::MaxFunction
- Jennifer::QueryBuilder::MinFunction
- Jennifer::QueryBuilder::NowFunction
- Jennifer::QueryBuilder::RoundFunction
- Jennifer::QueryBuilder::SumFunction
- Jennifer::QueryBuilder::UpperFunction
Defined in:
jennifer/query_builder/function.crConstructors
Instance Method Summary
- #alias_tables(aliases)
- #change_table(old_name, new_name)
-
#clone
NOTE can't be abstract because is already implemented by super class
- #definition(sql_generator)
- #definition
-
#filterable?
Returns whether node has an argument to be added to SQL statement arguments.
-
#operand_sql(operand : SQLNode, generator)
Translates given SQL node to SQL using generator.
-
#operand_sql(_operand, generator)
Translates given literal to SQL using generator.
-
#operands : Array(Array(Array(Char) | Array(Float32) | Array(Float64) | Array(Int16) | Array(Int32) | Array(Int64) | Array(String) | Bool | Char | Float32 | Float64 | Int16 | Int32 | Int64 | Int8 | JSON::Any | PG::Geo::Box | PG::Geo::Circle | PG::Geo::Line | PG::Geo::LineSegment | PG::Geo::Path | PG::Geo::Point | PG::Geo::Polygon | PG::Numeric | Slice(UInt8) | String | Time | Time::Span | UInt32 | UUID | Nil) | Array(Char) | Array(Float32) | Array(Float64) | Array(Int16) | Array(Int32) | Array(Int64) | Array(String) | Bool | Char | Float32 | Float64 | Int16 | Int32 | Int64 | Int8 | JSON::Any | Jennifer::QueryBuilder::SQLNode | PG::Geo::Box | PG::Geo::Circle | PG::Geo::Line | PG::Geo::LineSegment | PG::Geo::Path | PG::Geo::Point | PG::Geo::Polygon | PG::Numeric | Slice(UInt8) | String | Time | Time::Span | UInt32 | UUID | Nil)
Array of arguments that were passed to the function.
-
#operands_to_sql(generator)
Translates all operands to SQL using generator.
- #set_relation(table, name)
-
#sql_args : Array(DBAny)
Returns array of SQL query arguments.
Macro Summary
-
define(name, klass = nil, arity = 0, comment = nil)
Defines new function class.
Instance methods inherited from class Jennifer::QueryBuilder::Criteria
!=(value : Symbol)!=(value : Rightable) !=, &(other : LogicOperator::Operandable) &, *(value : Rightable) *, +(value : Rightable) +, -(value : Rightable) -, /(value : Rightable) /, <(value : Rightable) <, <=(value : Rightable) <=, ==(value : Symbol)
==(value : Rightable) ==, =~(value : String) =~, >(value : Rightable) >, >=(value : Rightable) >=, [](key) [], alias(name : String?)
alias : String? alias, alias_tables(aliases : Hash(String, String)) alias_tables, as_sql(generator) : String as_sql, asc asc, between(left : Rightable, right : Rightable) between, change_table(old_name : String, new_name : String) change_table, clone clone, contain(value : Rightable) contain, contained(value : Rightable) contained, definition(sql_generator)
definition definition, desc desc, eql?(other : Criteria) eql?, equal(value : Rightable) equal, field : String field, filterable? filterable?, hash(hasher) hash, identifier(sql_generator)
identifier : String identifier, ilike(value : Rightable) ilike, in(arr : Array)
in(arr : SQLNode) in, is(value : Symbol | Bool | Nil) is, like(value : Rightable) like, not(value : Symbol | Bool | Nil)
not not, not_equal(value) not_equal, not_like(value : Rightable) not_like, not_regexp(value : Rightable) not_regexp, order(direction : String | Symbol) order, overlap(value : Rightable) overlap, path(elements : String) path, regexp(value : Rightable) regexp, relation : String? relation, set_relation(table : String, name : String) set_relation, sql_args : Array(DBAny) sql_args, table : String table, take(key : String | Number) take, to_s(io : IO) to_s, xor(other : LogicOperator::Operandable) xor, |(other : LogicOperator::Operandable) |
Constructor methods inherited from class Jennifer::QueryBuilder::Criteria
new(field : String, table : String, relation = nil)
new
Instance methods inherited from class Jennifer::QueryBuilder::SQLNode
alias_tables(aliases)
alias_tables,
as_sql
as_sql,
change_table(old_name, new_name)
change_table,
eql?(other)
eql?,
set_relation(table, name)
set_relation,
to_condition
to_condition
Instance methods inherited from module Jennifer::QueryBuilder::Statement
as_sql(sql_generator)
as_sql,
filterable?
filterable?,
sql_args : Array(DBAny)
sql_args
Constructor Detail
Instance Method Detail
Returns whether node has an argument to be added to SQL statement arguments.
Translates given SQL node to SQL using generator.
def as_sql(generator)
"ABS(#{operand_sql(operands[0], generator)})"
end
Translates given literal to SQL using generator.
def as_sql(generator)
"ABS(#{operand_sql(operands[0], generator)})"
end
Array of arguments that were passed to the function.
Translates all operands to SQL using generator.
def as_sql(generator)
"CONCAT(#{operands_to_sql(generator)})"
end
Returns array of SQL query arguments.
Macro Detail
Defines new function class.
name
- function name; use used to generate function class name if it isn't specifiedklass
- function class name; optionalarity
- describes function aritycomment
- adds given comment to the generated function class.
arity
= -1 means function can accept variable number of argument, 0 - no one.
In the block you can define any methods you like but must implement #as_sql
abstract method.
To access arguments passed to the function use #operands
method.
Function.define("lower", arity: 1, comment: <<-TEXT
Creates `LOWER` SQL function instance with the given
next line
```
1 + 2
```
TEXT
) do
def as_sql(generator)
"LOWER(#{operand_sql(operands[0], generator)})"
end
end