|
| 1 | +@code_instead QueryOperators.drop SourceCode Integer |
| 2 | +@simple_translate ::typeof(QueryOperators.drop) :OFFSET |
| 3 | + |
| 4 | +@code_instead QueryOperators.filter SourceCode Any Expr |
| 5 | +function translate_dispatch(::typeof(QueryOperators.filter), iterator, call, call_expression) |
| 6 | + SQLExpression(:WHERE, |
| 7 | + translate(iterator), |
| 8 | + translate(call(model_row(iterator)).code) |
| 9 | + ) |
| 10 | +end |
| 11 | + |
| 12 | +@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)) |
| 21 | + ) |
| 22 | +end |
| 23 | + |
| 24 | +@code_instead QueryOperators.orderby SourceCode Any Expr |
| 25 | +function translate_dispatch(::typeof(QueryOperators.orderby), unordered, key_function, key_function_expression) |
| 26 | + SQLExpression(Symbol("ORDER BY"), |
| 27 | + translate(unordered), |
| 28 | + translate(key_function(model_row(unordered)).code) |
| 29 | + ) |
| 30 | +end |
| 31 | +@code_instead QueryOperators.thenby SourceCode Any Expr |
| 32 | +function translate_dispatch(::typeof(QueryOperators.thenby), unordered, key_function, key_function_expression) |
| 33 | + original = translate(unordered) |
| 34 | + SQLExpression(original.call, original.arguments..., |
| 35 | + translate(key_function(model_row(unordered)).code) |
| 36 | + ) |
| 37 | +end |
| 38 | + |
| 39 | +@code_instead QueryOperators.orderby_descending SourceCode Any Expr |
| 40 | +function translate_dispatch(::typeof(QueryOperators.orderby_descending), unordered, key_function, key_function_expression) |
| 41 | + SQLExpression(Symbol("ORDER BY"), |
| 42 | + translate(unordered), |
| 43 | + SQLExpression(:DESC, |
| 44 | + translate(key_function(model_row(unordered)).code) |
| 45 | + ) |
| 46 | + ) |
| 47 | +end |
| 48 | +@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) |
| 51 | + SQLExpression(original.call, original.arguments..., |
| 52 | + SQLExpression(:DESC, |
| 53 | + translate(key_function(model_row(unordered)).code) |
| 54 | + ) |
| 55 | + ) |
| 56 | +end |
| 57 | + |
| 58 | +@code_instead QueryOperators.map SourceCode Any Expr |
| 59 | +function model_row_dispatch(::typeof(QueryOperators.map), iterator, call, call_expression) |
| 60 | + call(model_row(iterator)) |
| 61 | +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) |
| 69 | + SQLExpression( |
| 70 | + Symbol("SELECT"), translate(select_table), |
| 71 | + Generator(select_as, pairs(call(model_row(select_table))))... |
| 72 | + ) |
| 73 | +end |
| 74 | + |
| 75 | +@code_instead QueryOperators.take SourceCode Any |
| 76 | +@simple_translate ::typeof(QueryOperators.take) :LIMIT |
| 77 | + |
| 78 | +@code_instead QueryOperators.unique SourceCode Any Expr |
| 79 | +function translate_dispatch(::typeof(QueryOperators.unique), repeated, key_function, key_function_expression) |
| 80 | + result = translate(repeated) |
| 81 | + SQLExpression(Symbol(string(result.call, " DISTINCT")), result.arguments...) |
| 82 | +end |
0 commit comments