Skip to content

Commit

Permalink
Merge pull request #36 from queryverse/create-pull-request/patch
Browse files Browse the repository at this point in the history
[AUTO] Format files using DocumentFormat
  • Loading branch information
bramtayl authored Sep 13, 2020
2 parents 4645117 + 6049c2f commit 8bcd162
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions coverage/submit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
submit(
filter(
let prefix = joinpath(pwd(), "src", "")
coverage->startswith(coverage.filename, prefix)
end,
coverage -> startswith(coverage.filename, prefix)
end,
readfolder(".")
)
)
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Documenter: deploydocs, makedocs
using QuerySQLite

makedocs(sitename = "QuerySQLite.jl", modules = [QuerySQLite], doctest = false)
deploydocs(repo = "github.com/queryverse/QuerySQLite.jl.git")
makedocs(sitename="QuerySQLite.jl", modules=[QuerySQLite], doctest=false)
deploydocs(repo="github.com/queryverse/QuerySQLite.jl.git")
2 changes: 1 addition & 1 deletion src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ julia> hex("hello")
```
"""
function hex(it::Number)
uppercase(string(it, base = 16))
uppercase(string(it, base=16))
end
function hex(it::AbstractString)
join(hex(byte) for byte in codeunits(it))
Expand Down
6 changes: 3 additions & 3 deletions src/iterate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function second((value_1, value_2))
value_2
end

function name_and_type(handle, column_number, nullable = true, strict_types = true)
function name_and_type(handle, column_number, nullable=true, strict_types=true)
Symbol(unsafe_string(sqlite3_column_name(handle, column_number))),
if strict_types
julia_type = juliatype(handle, column_number)
Expand All @@ -118,8 +118,8 @@ function getiterator(source_code::SourceCode)
handle = statement.handle
schema = ntuple(
let handle = handle
column_number->name_and_type(handle, column_number)
end,
column_number -> name_and_type(handle, column_number)
end,
sqlite3_column_count(handle)
)
SQLiteCursor{NamedTuple{Tuple(map(first, schema)),Tuple{map(second, schema)...}}}(statement, Ref(status), Ref(0))
Expand Down
116 changes: 58 additions & 58 deletions src/translate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ function nest(sql_expression)
SQLExpression(:AS, SQLExpression(:FROM, sql_expression), :__TABLE__)
end

function translate(something::Union{Char,AbstractString}; _primary = true)
function translate(something::Union{Char,AbstractString}; _primary=true)
repr(something)
end

function translate(something; _primary = true)
function translate(something; _primary=true)
something
end
function translate(source_row::SourceRow; _primary = true)
function translate(source_row::SourceRow; _primary=true)
source_row.table_name
end
function translate(call::Expr; _primary = true)
function translate(call::Expr; _primary=true)
arguments, keywords = split_call(call)
translate_call(arguments...; _primary = _primary, keywords...)
translate_call(arguments...; _primary=_primary, keywords...)
end

# A 1-1 mapping between Julia functions and SQL functions
function translate_default(location, function_type, SQL_call)
result = :(
function translate_call($function_type, arguments...; _primary = true)
$SQLExpression($SQL_call, $map(
argument->$translate(argument; _primary = _primary),
function translate_call($function_type, arguments...; _primary=true)
$SQLExpression($SQL_call, $map(
argument -> $translate(argument; _primary=_primary),
arguments
)...)
end
end
)
result.args[2].args[1] = location
result
Expand Down Expand Up @@ -65,9 +65,9 @@ end

@translate_default ::typeof(abs) :ABS

function as(pair; _primary = true)
function as(pair; _primary=true)
SQLExpression(:AS,
translate(pair.second.code; _primary = _primary),
translate(pair.second.code; _primary=_primary),
pair.first
)
end
Expand All @@ -76,56 +76,56 @@ end

@translate_default ::typeof(char) :CHAR

function translate_call(::typeof(convert), ::Type{Int}, it; _primary = true)
function translate_call(::typeof(convert), ::Type{Int}, it; _primary=true)
SQLExpression(:UNICODE, translate(it))
end

@translate_default ::typeof(hex) :HEX

@translate_default ::typeof(QueryOperators.drop) :OFFSET

function translate_call(::typeof(QueryOperators.filter), iterator, call, call_expression; _primary = true)
function translate_call(::typeof(QueryOperators.filter), iterator, call, call_expression; _primary=true)
SQLExpression(:WHERE,
translate(iterator; _primary = _primary),
translate(call(model_row(iterator)).code; _primary = _primary)
translate(iterator; _primary=_primary),
translate(call(model_row(iterator)).code; _primary=_primary)
)
end

function translate_call(::typeof(format), time_type, format_string; _primary = true)
function translate_call(::typeof(format), time_type, format_string; _primary=true)
SQLExpression(
:STRFTIME,
translate(format_string; _primary = _primary),
translate(time_type; _primary = _primary)
translate(format_string; _primary=_primary),
translate(time_type; _primary=_primary)
)
end

function translate_call(::typeof(getproperty), source_tables::Database, table_name; _primary = true)
translated = translate(table_name; _primary = _primary)
function translate_call(::typeof(getproperty), source_tables::Database, table_name; _primary=true)
translated = translate(table_name; _primary=_primary)
if _primary
SQLExpression(:FROM, translated)
else
translated
end
end
function translate_call(::typeof(getproperty), source_row::SourceRow, column_name; _primary = true)
translated = translate(column_name; _primary = _primary)
function translate_call(::typeof(getproperty), source_row::SourceRow, column_name; _primary=true)
translated = translate(column_name; _primary=_primary)
if _primary
translated
else
SQLExpression(:., source_row.table_name, translated)
end
end

function translate_call(::typeof(QueryOperators.groupby), ungrouped, group_function, group_function_expression, map_selector, map_function_expression; _primary = true)
function translate_call(::typeof(QueryOperators.groupby), ungrouped, group_function, group_function_expression, map_selector, map_function_expression; _primary=true)
model = model_row(ungrouped)
SQLExpression(Symbol("GROUP BY"),
nest(translate_call(
QueryOperators.map,
ungrouped,
map_selector, map_function_expression,
_primary = _primary
_primary=_primary
)),
translate(group_function(model).code; _primary = _primary)
translate(group_function(model).code; _primary=_primary)
)
end

Expand All @@ -143,25 +143,25 @@ end

@translate_default ::typeof(join) :GROUP_CONCAT

function translate_call(::typeof(QueryOperators.join), source1, source2, key1, key1_expression, key2, key2_expression, combine, combine_expression; _primary = true)
function translate_call(::typeof(QueryOperators.join), source1, source2, key1, key1_expression, key2, key2_expression, combine, combine_expression; _primary=true)
model_row_1 = model_row(source1)
model_row_2 = model_row(source2)
SQLExpression(:SELECT,
SQLExpression(:ON,
SQLExpression(Symbol("INNER JOIN"),
translate(source1),
# mark as not _primary to suppress FROM
translate(source2; _primary = false)
translate(source2; _primary=false)
),
# mark both as not _primary to always be explicit about table
SQLExpression(:(=),
translate(key1(model_row_1).code; _primary = false),
translate(key2(model_row_2).code; _primary = false)
translate(key1(model_row_1).code; _primary=false),
translate(key2(model_row_2).code; _primary=false)
)
),
# mark both as not _primary to always be explicit about table
Generator(
pair->as(pair; _primary = false),
pair -> as(pair; _primary=false),
pairs(combine(model_row_1, model_row_2))
)...
)
Expand All @@ -171,15 +171,15 @@ end

@translate_default ::typeof(lowercase) :LOWER

function translate_call(::typeof(QueryOperators.map), select_table, call, call_expression; _primary = true)
inner = translate(select_table; _primary = _primary)
function translate_call(::typeof(QueryOperators.map), select_table, call, call_expression; _primary=true)
inner = translate(select_table; _primary=_primary)
if inner.call == :SELECT
inner = nest(inner)
end
SQLExpression(
:SELECT, inner,
Generator(
pair->as(pair; _primary = _primary),
pair -> as(pair; _primary=_primary),
pairs(call(model_row(select_table)))
)...
)
Expand All @@ -193,49 +193,49 @@ end
@translate_default ::typeof(min) :min
@translate_default ::typeof(minimum) :min

translate_call(::typeof(occursin), needle, haystack; _primary = true) =
translate_call(::typeof(occursin), needle, haystack; _primary=true) =
SQLExpression(
:LIKE,
translate(haystack; _primary = _primary),
translate(needle; _primary = _primary)
translate(haystack; _primary=_primary),
translate(needle; _primary=_primary)
)

function translate_call(::typeof(QueryOperators.orderby), unordered, key_function, key_function_expression; _primary = true)
function translate_call(::typeof(QueryOperators.orderby), unordered, key_function, key_function_expression; _primary=true)
SQLExpression(Symbol("ORDER BY"),
translate(unordered; _primary = _primary),
translate(key_function(model_row(unordered)).code; _primary = _primary)
translate(unordered; _primary=_primary),
translate(key_function(model_row(unordered)).code; _primary=_primary)
)
end

function translate_call(::typeof(QueryOperators.orderby_descending), unordered, key_function, key_function_expression; _primary = true)
function translate_call(::typeof(QueryOperators.orderby_descending), unordered, key_function, key_function_expression; _primary=true)
SQLExpression(Symbol("ORDER BY"),
translate(unordered; _primary = _primary),
translate(unordered; _primary=_primary),
SQLExpression(:DESC,
translate(key_function(model_row(unordered)).code; _primary = _primary)
translate(key_function(model_row(unordered)).code; _primary=_primary)
)
)
end

@translate_default ::typeof(repr) :QUOTE

function translate_call(::typeof(rand), ::Type{Int}; _primary = true)
function translate_call(::typeof(rand), ::Type{Int}; _primary=true)
SQLExpression(:RANDOM)
end

@translate_default ::typeof(randstring) :RANDOMBLOB

function translate_call(::typeof(replace), it, pair; _primary = true)
function translate_call(::typeof(replace), it, pair; _primary=true)
SQLExpression(:REPLACE,
translate(it; _primary = _primary),
translate(pair.first; _primary = _primary),
translate(pair.second; _primary = _primary)
translate(it; _primary=_primary),
translate(pair.first; _primary=_primary),
translate(pair.second; _primary=_primary)
)
end

function translate_call(::typeof(round), it; _primary = true, digits = 0)
function translate_call(::typeof(round), it; _primary=true, digits=0)
SQLExpression(:ROUND,
translate(it; _primary = _primary),
translate(digits; _primary = _primary)
translate(it; _primary=_primary),
translate(digits; _primary=_primary)
)
end

Expand All @@ -249,26 +249,26 @@ end

@translate_default ::typeof(QueryOperators.take) :LIMIT

function translate_call(::typeof(QueryOperators.thenby), unordered, key_function, key_function_expression; _primary = true)
original = translate(unordered; _primary = _primary)
function translate_call(::typeof(QueryOperators.thenby), unordered, key_function, key_function_expression; _primary=true)
original = translate(unordered; _primary=_primary)
SQLExpression(original.call, original.arguments...,
translate(key_function(model_row(unordered)).code; _primary = _primary)
translate(key_function(model_row(unordered)).code; _primary=_primary)
)
end

function translate_call(::typeof(QueryOperators.thenby_descending), unordered, key_function, key_function_expression; _primary = true)
original = translate(unordered; _primary = _primary)
function translate_call(::typeof(QueryOperators.thenby_descending), unordered, key_function, key_function_expression; _primary=true)
original = translate(unordered; _primary=_primary)
SQLExpression(original.call, original.arguments...,
SQLExpression(:DESC,
translate(key_function(model_row(unordered)).code; _primary = _primary)
translate(key_function(model_row(unordered)).code; _primary=_primary)
)
)
end

@translate_default ::typeof(type_of) :TYPEOF

function translate_call(::typeof(QueryOperators.unique), repeated, key_function, key_function_expression; _primary = true)
result = translate(repeated; _primary = _primary)
function translate_call(::typeof(QueryOperators.unique), repeated, key_function, key_function_expression; _primary=true)
result = translate(repeated; _primary=_primary)
SQLExpression(Symbol(string(result.call, " DISTINCT")), result.arguments...)
end

Expand Down

0 comments on commit 8bcd162

Please sign in to comment.