@@ -13,13 +13,15 @@ function translate(source_row::SourceRow; primary = true)
1313 source_row. table_name
1414end
1515function translate (call:: Expr ; primary = true )
16- translate_call (split_call (call)... ; primary = primary)
16+ arguments, keywords = split_call (call)
17+ # TODO : figure out a way for users to pass a keyword named primary
18+ translate_call (arguments... ; primary = primary, keywords... )
1719end
1820
1921# A 1-1 mapping between Julia functions and SQL functions
20- function translate_default (location, a_function , SQL_call)
22+ function translate_default (location, function_type , SQL_call)
2123 result = :(
22- function translate_call (:: typeof ( $ a_function) , arguments... ; primary = true )
24+ function translate_call ($ function_type , arguments... ; primary = true )
2325 $ SQLExpression ($ SQL_call, $ map_unrolled (
2426 argument -> $ translate (argument; primary = primary),
2527 arguments
@@ -34,15 +36,23 @@ macro translate_default(a_function, SQL_call)
3436 translate_default (__source__, a_function, SQL_call) |> esc
3537end
3638
37- @translate_default (== ) :(= )
39+ @translate_default :: typeof (== ) :(= )
3840
39- @translate_default (!= ) Symbol (" <>" )
41+ @translate_default :: typeof (!= ) Symbol (" <>" )
4042
41- @translate_default (! ) :NOT
43+ @translate_default :: typeof (! ) :NOT
4244
43- @translate_default (& ) :AND
45+ @translate_default :: typeof (& ) :AND
4446
45- @translate_default (| ) :OR
47+ @translate_default :: typeof (| ) :OR
48+
49+ @translate_default :: typeof (* ) :*
50+
51+ @translate_default :: typeof (+ ) :+
52+
53+ @translate_default :: typeof (% ) :%
54+
55+ @translate_default :: typeof (abs) :ABS
4656
4757function as (pair; primary = true )
4858 SQLExpression (:AS ,
@@ -51,9 +61,11 @@ function as(pair; primary = true)
5161 )
5262end
5363
54- @translate_default coalesce :COALESCE
64+ @translate_default :: Type{Char} :CHAR
65+
66+ @translate_default :: typeof (coalesce) :COALESCE
5567
56- @translate_default QueryOperators. drop :OFFSET
68+ @translate_default :: typeof ( QueryOperators. drop) :OFFSET
5769
5870function translate_call (:: typeof (QueryOperators. filter), iterator, call, call_expression; primary = true )
5971 SQLExpression (:WHERE ,
@@ -88,15 +100,15 @@ function translate_call(::typeof(QueryOperators.groupby), ungrouped, group_funct
88100 )
89101end
90102
91- @translate_default if_else :CASE
103+ @translate_default :: typeof ( if_else) :CASE
92104
93- @translate_default in :IN
105+ @translate_default :: typeof (in) :IN
94106
95- @translate_default isequal Symbol (" IS NOT DISTINCT FROM" )
107+ @translate_default :: typeof ( isequal) Symbol (" IS NOT DISTINCT FROM" )
96108
97- @translate_default isless :<
109+ @translate_default :: typeof ( isless) :<
98110
99- @translate_default ismissing Symbol (" IS NULL" )
111+ @translate_default :: typeof ( ismissing) Symbol (" IS NULL" )
100112
101113function translate_call (:: typeof (QueryOperators. join), source1, source2, key1, key1_expression, key2, key2_expression, combine, combine_expression; primary = true )
102114 model_row_1 = model_row (source1)
@@ -122,7 +134,9 @@ function translate_call(::typeof(QueryOperators.join), source1, source2, key1, k
122134 )
123135end
124136
125- @translate_default length :COUNT
137+ @translate_default :: typeof (length) :COUNT
138+
139+ @translate_default :: typeof (lowercase) :LOWER
126140
127141function translate_call (:: typeof (QueryOperators. map), select_table, call, call_expression; primary = true )
128142 SQLExpression (
@@ -134,6 +148,10 @@ function translate_call(::typeof(QueryOperators.map), select_table, call, call_e
134148 )
135149end
136150
151+ @translate_default :: typeof (max) :max
152+
153+ @translate_default :: typeof (min) :min
154+
137155translate_call (:: typeof (occursin), needle:: AbstractString , haystack; primary = true ) =
138156 SQLExpression (
139157 :LIKE ,
@@ -147,7 +165,7 @@ translate_call(::typeof(occursin), needle::Regex, haystack; primary = true) =
147165 # * => %, . => _
148166 replace (replace (needle. pattern, r" (?<!\\ )\.\* " => " %" ), r" (?<!\\ )\. " => " _" )
149167 )
150- @translate_default occursin :LIKE
168+ @translate_default :: typeof ( occursin) :LIKE
151169
152170function translate_call (:: typeof (QueryOperators. orderby), unordered, key_function, key_function_expression; primary = true )
153171 SQLExpression (Symbol (" ORDER BY" ),
@@ -172,7 +190,9 @@ translate_call(::typeof(startswith), full, prefix::AbstractString; primary = pri
172190 string (prefix, ' %' )
173191 )
174192
175- @translate_default QueryOperators. take :LIMIT
193+ @translate_default :: typeof (string) :||
194+
195+ @translate_default :: typeof (QueryOperators. take) :LIMIT
176196
177197function translate_call (:: typeof (QueryOperators. thenby), unordered, key_function, key_function_expression; primary = true )
178198 original = translate (unordered; primary = primary)
@@ -194,3 +214,5 @@ function translate_call(::typeof(QueryOperators.unique), repeated, key_function,
194214 result = translate (repeated; primary = primary)
195215 SQLExpression (Symbol (string (result. call, " DISTINCT" )), result. arguments... )
196216end
217+
218+ @translate_default :: typeof (uppercase) :UPPER
0 commit comments