-
Notifications
You must be signed in to change notification settings - Fork 0
Common Patterns
Alex edited this page Jul 29, 2018
·
2 revisions
Structure:
-
Array
- first element -
Symbol
that begins from _ -:_nullif
- arguments
- first element -
[:_count, [:_nullif, :row, [:_params, 'mrgl']]] # TODO: param?
# => ['COUNT(NULLIF(row, $1))', ['mrgl']]
Detailed Operators description.
Possible structures:
-
String
- if it locted in the
Hash
with table alias, table alias will be added to it - if there is no table alias it will be returned to the builder as it is.
- if it locted in the
-
Symbol
- just parsed to string -
Hash
- key - table alias||name
- value - columns
- SQL operator
- Sub Query
-
Array
- holder of any possible structures
['name', {u: ['role', 'u.phone, m.rating', :field]}]
# => 'name, u.role, u.phone, m.rating, u.field'
Possible structures:
-
String
||Symbol
- SQL operator
-
Array
- if there is no
Array
inside it will be joinedstructure.join ' '
-
Array
with any tables structure.
- if there is no
['users u', [:_values, ...], [:masters, :m]]
'users u, (VALUES...), masters m'
Not finished yet...
Column can be described as :u__name => 'u.name'
or :name
Possible structures:
-
String
passes as it is -
Hash
represent sql=
orIN
if value isArray
. TODO:IS
in case ofnil
orfalse
-
Symbol
- column name -
Array
- only as value! will be placed in querry params($1)
. -
String
- will be placed in querry params
-
-
Array
- first element -
Symbol
operator representation, by default:and
-
eq
-=
-
or
,and
in
not
-
like
,ilike
-
reg
-~
,reg_i
-~*
,reg_f
-!~
,reg_fi
-!~*
-
- arguments
- first element -
-
Array
- holder of any possible structures
[[:not, 'z = 13'],
[:or, 'mrgl = 2', 'rgl = 22'],
[:or, 'rgl = 12', 'zgl = lol']]
# => 'NOT z = 13 AND (mrgl = 2 OR rgl = 22) AND (rgl = 12 OR zgl = lol)'
[{ role: 'manager', id: [0, 1, 153] },
[:not, [:like, :u__name, 'Aeonax']]]
#=> 'role = $1 AND id IN ($2) AND NOT u.name LIKE $3', ['manager', [0, 1, 153], 'Aeonax']
Possible structures:
-
Constructor
instance -
Hash
with:select
value