|
| 1 | +function as(new_name_model_row::Pair{Symbol, <: SourceCode}; options...) |
| 2 | + SQLExpression(:AS, |
| 3 | + translate(new_name_model_row.second.code; options...), |
| 4 | + new_name_model_row.first |
| 5 | + ) |
| 6 | +end |
| 7 | + |
1 | 8 | @code_instead QueryOperators.drop SourceCode Integer |
2 | | -@simple_translate ::typeof(QueryOperators.drop) :OFFSET |
| 9 | +@translate ::typeof(QueryOperators.drop) :OFFSET |
3 | 10 |
|
4 | 11 | @code_instead QueryOperators.filter SourceCode Any Expr |
5 | | -function translate_dispatch(::typeof(QueryOperators.filter), iterator, call, call_expression) |
| 12 | +function translate_dispatch(::typeof(QueryOperators.filter), iterator, call, call_expression; options...) |
6 | 13 | SQLExpression(:WHERE, |
7 | | - translate(iterator), |
8 | | - translate(call(model_row(iterator)).code) |
| 14 | + translate(iterator; options...), |
| 15 | + translate(call(model_row(iterator)).code; options...) |
9 | 16 | ) |
10 | 17 | end |
11 | 18 |
|
12 | 19 | @code_instead QueryOperators.join SourceCode SourceCode Any Expr Any Expr Any Expr |
13 | | -function translate_dispatch(::typeof(QueryOperators.join), source1, source2, |
14 | | - key1, key1_expression, |
15 | | - key2, key2_expression, |
16 | | - combine, combine_expression |
17 | | -) |
18 | | - SQLExpression(:on, |
19 | | - SQLExpression(:INNER_JOIN, translate(source1), translate(source2)), |
20 | | - SQLExpression(:(=), translate(key1), translate(key2)) |
| 20 | +function translate_dispatch(::typeof(QueryOperators.join), source1, source2, key1, key1_expression, key2, key2_expression, combine, combine_expression; options...) |
| 21 | + model_row_1 = model_row(source1; other = true) |
| 22 | + model_row_2 = model_row(source2; other = true) |
| 23 | + SQLExpression(:ON, |
| 24 | + SQLExpression(Symbol("INNER JOIN"), |
| 25 | + SQLExpression(:SELECT, |
| 26 | + translate(source1; options...), |
| 27 | + Generator( |
| 28 | + pair -> as(pair; options...), |
| 29 | + pairs(combine(model_row_1, model_row_2)) |
| 30 | + )... |
| 31 | + ), |
| 32 | + translate(source2; other = true, options...) |
| 33 | + ), |
| 34 | + SQLExpression(:(=), |
| 35 | + translate(key1(model_row_1).code; options...), |
| 36 | + translate(key2(model_row_2).code; other = true, options...) |
| 37 | + ) |
21 | 38 | ) |
22 | 39 | end |
23 | 40 |
|
24 | 41 | @code_instead QueryOperators.orderby SourceCode Any Expr |
25 | | -function translate_dispatch(::typeof(QueryOperators.orderby), unordered, key_function, key_function_expression) |
| 42 | +function translate_dispatch(::typeof(QueryOperators.orderby), unordered, key_function, key_function_expression; options...) |
26 | 43 | SQLExpression(Symbol("ORDER BY"), |
27 | | - translate(unordered), |
28 | | - translate(key_function(model_row(unordered)).code) |
| 44 | + translate(unordered; options...), |
| 45 | + translate(key_function(model_row(unordered)).code; options...) |
29 | 46 | ) |
30 | 47 | end |
31 | 48 | @code_instead QueryOperators.thenby SourceCode Any Expr |
32 | | -function translate_dispatch(::typeof(QueryOperators.thenby), unordered, key_function, key_function_expression) |
33 | | - original = translate(unordered) |
| 49 | +function translate_dispatch(::typeof(QueryOperators.thenby), unordered, key_function, key_function_expression; options...) |
| 50 | + original = translate(unordered; options...) |
34 | 51 | SQLExpression(original.call, original.arguments..., |
35 | | - translate(key_function(model_row(unordered)).code) |
| 52 | + translate(key_function(model_row(unordered)).code; options...) |
36 | 53 | ) |
37 | 54 | end |
38 | 55 |
|
39 | 56 | @code_instead QueryOperators.orderby_descending SourceCode Any Expr |
40 | | -function translate_dispatch(::typeof(QueryOperators.orderby_descending), unordered, key_function, key_function_expression) |
| 57 | +function translate_dispatch(::typeof(QueryOperators.orderby_descending), unordered, key_function, key_function_expression; options...) |
41 | 58 | SQLExpression(Symbol("ORDER BY"), |
42 | | - translate(unordered), |
| 59 | + translate(unordered; options...), |
43 | 60 | SQLExpression(:DESC, |
44 | | - translate(key_function(model_row(unordered)).code) |
| 61 | + translate(key_function(model_row(unordered)).code; options...) |
45 | 62 | ) |
46 | 63 | ) |
47 | 64 | end |
48 | 65 | @code_instead QueryOperators.thenby_descending SourceCode Any Expr |
49 | | -function translate_dispatch(::typeof(QueryOperators.thenby_descending), unordered, key_function, key_function_expression) |
50 | | - original = translate(unordered) |
| 66 | +function translate_dispatch(::typeof(QueryOperators.thenby_descending), unordered, key_function, key_function_expression; options...) |
| 67 | + original = translate(unordered; options...) |
51 | 68 | SQLExpression(original.call, original.arguments..., |
52 | 69 | SQLExpression(:DESC, |
53 | | - translate(key_function(model_row(unordered)).code) |
| 70 | + translate(key_function(model_row(unordered)).code; options...) |
54 | 71 | ) |
55 | 72 | ) |
56 | 73 | end |
57 | 74 |
|
58 | 75 | @code_instead QueryOperators.map SourceCode Any Expr |
59 | | -function model_row_dispatch(::typeof(QueryOperators.map), iterator, call, call_expression) |
60 | | - call(model_row(iterator)) |
| 76 | +function model_row_dispatch(::typeof(QueryOperators.map), iterator, call, call_expression; options...) |
| 77 | + call(model_row(iterator; options...)) |
61 | 78 | end |
62 | | -function select_as(new_name_model_row::Pair{Symbol, <: SourceCode}) |
63 | | - SQLExpression(:AS, |
64 | | - new_name_model_row.first, |
65 | | - translate(new_name_model_row.second.code), |
66 | | - ) |
67 | | -end |
68 | | -function translate_dispatch(::typeof(QueryOperators.map), select_table, call, call_expression) |
| 79 | + |
| 80 | +function translate_dispatch(::typeof(QueryOperators.map), select_table, call, call_expression; options...) |
69 | 81 | SQLExpression( |
70 | | - Symbol("SELECT"), translate(select_table), |
71 | | - Generator(select_as, pairs(call(model_row(select_table))))... |
| 82 | + Symbol("SELECT"), translate(select_table; options...), |
| 83 | + Generator( |
| 84 | + pair -> as(pair; options...), |
| 85 | + pairs(call(model_row(select_table; options...))) |
| 86 | + )... |
72 | 87 | ) |
73 | 88 | end |
74 | 89 |
|
75 | 90 | @code_instead QueryOperators.take SourceCode Any |
76 | | -@simple_translate ::typeof(QueryOperators.take) :LIMIT |
| 91 | +@translate ::typeof(QueryOperators.take) :LIMIT |
77 | 92 |
|
78 | 93 | @code_instead QueryOperators.unique SourceCode Any Expr |
79 | | -function translate_dispatch(::typeof(QueryOperators.unique), repeated, key_function, key_function_expression) |
80 | | - result = translate(repeated) |
| 94 | +function translate_dispatch(::typeof(QueryOperators.unique), repeated, key_function, key_function_expression; options...) |
| 95 | + result = translate(repeated; options...) |
81 | 96 | SQLExpression(Symbol(string(result.call, " DISTINCT")), result.arguments...) |
82 | 97 | end |
0 commit comments