Skip to content

Commit a886be8

Browse files
authored
[Rel v0.2] Migrate api.jl to the new language standard (#126)
1 parent e1ba8da commit a886be8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/api.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,15 @@ completed, and returns a Dict holding the Transaction resource and its results a
542542
543543
# Examples:
544544
```julia
545-
julia> exec(ctx, "my_database", "my_engine", "2 + 2")
545+
julia> exec(ctx, "my_database", "my_engine", "def output {2 + 2}")
546546
Dict{String, Any} with 4 entries:
547547
"metadata" => Union{}[]
548548
"problems" => Union{}[]
549549
"results" => Pair{String, Arrow.Table}["/:output/Int64"=>Arrow.Table with 1 r…
550550
"transaction" => {…
551551
552552
julia> exec(ctx, "my_database", "my_engine", \"""
553-
def insert:my_relation = 1, 2, 3
553+
def insert[:my_relation]: (1, 2, 3)
554554
\""",
555555
readonly = false,
556556
)
@@ -712,7 +712,7 @@ function _gen_literal(value)
712712
end
713713

714714
function _gen_literal(value::Dict)
715-
items = ["$(_gen_literal(v)),$(_gen_literal(k))" for (k, v) in value]
715+
items = ["($(_gen_literal(v)),$(_gen_literal(k)))" for (k, v) in value]
716716
return "{" + join(items, ";") + "}"
717717
end
718718

@@ -725,12 +725,12 @@ _gen_literal(value::Symbol) = ":$value"
725725

726726
function _gen_literal(value::Vector)
727727
items = [_gen_literal(item) for item in value]
728-
return "{" + join(items, ",") + "}"
728+
return "{(" + join(items, ",") + ")}"
729729
end
730730

731731
function _gen_config(name, value)
732732
isnothing(value) && return ""
733-
return "def config:syntax:$name=$(_gen_literal(value))"
733+
return "def config[:syntax, :$name]: $(_gen_literal(value))"
734734
end
735735

736736
function _gen_config(syntax::Dict)
@@ -761,8 +761,8 @@ function load_csv(
761761
"escapechar" => escapechar,
762762
"quotechar" => quotechar)
763763
source = _gen_config(syntax)
764-
source *= """def config:data = data
765-
def insert:$relation = load_csv[config]"""
764+
source *= """def config[:data]: data
765+
def insert[:$relation]: load_csv[config]"""
766766
return exec(ctx, database, engine, source; inputs = inputs, readonly = false, kw...)
767767
end
768768

@@ -771,8 +771,8 @@ end
771771
# todo: data should be string or io
772772
function load_json(ctx::Context, database::AbstractString, engine::AbstractString, relation::AbstractString, data; kw...)
773773
inputs = Dict("data" => _read_data(data))
774-
source = """def config:data = data\n
775-
def insert:$relation = load_json[config]"""
774+
source = """def config[:data]: data\n
775+
def insert[:$relation]: load_json[config]"""
776776
return exec(ctx, database, engine, source; inputs = inputs, readonly = false, kw...)
777777
end
778778

@@ -785,8 +785,8 @@ function load_models(ctx::Context, database::AbstractString, engine::AbstractStr
785785
for (name, value) in models
786786
input_name = string("input_", rand_uint, "_", index)
787787
push!(queries, """
788-
def delete:rel:catalog:model["$name"] = rel:catalog:model["$name"]
789-
def insert:rel:catalog:model["$name"] = $input_name
788+
def delete[:rel, :catalog, :model, "$name"]: rel[:catalog, :model, "$name"]
789+
def insert[:rel, :catalog, :model, "$name"]: $input_name
790790
""")
791791

792792
queries_inputs[input_name] = value
@@ -805,8 +805,8 @@ function load_models_async(ctx::Context, database::AbstractString, engine::Abstr
805805
for (name, value) in models
806806
input_name = string("input_", rand_uint, "_", index)
807807
push!(queries, """
808-
def delete:rel:catalog:model["$name"] = rel:catalog:model["$name"]
809-
def insert:rel:catalog:model["$name"] = $input_name
808+
def delete[:rel, :catalog, :model, "$name"]: rel[:catalog, :model, "$name"]
809+
def insert[:rel, :catalog, :model, "$name"]: $input_name
810810
""")
811811

812812
queries_inputs[input_name] = value
@@ -818,7 +818,7 @@ end
818818

819819
function list_models(ctx::Context, database::AbstractString, engine::AbstractString; kw...)
820820
out_name = "model$(rand(UInt64))"
821-
query = """ def output:$out_name[name] = rel:catalog:model(name, _) """
821+
query = """ def output(:$out_name, name): rel(:catalog, :model, name, _) """
822822
resp = exec(ctx, database, engine, query)
823823
for result in resp.results
824824
if occursin("/:output/:$out_name", result.first)
@@ -829,7 +829,7 @@ end
829829

830830
function get_model(ctx::Context, database::AbstractString, engine::AbstractString, name::AbstractString; kw...)
831831
out_name = "model$(rand(UInt64))"
832-
query = """def output:$out_name = rel:catalog:model[$(_escape_string_for_rel(name))]"""
832+
query = """def output[:$out_name]: rel[:catalog, :model, $(_escape_string_for_rel(name))]"""
833833
resp = exec(ctx, database, engine, query)
834834
for result in resp.results
835835
if occursin("/:output/:$out_name", result.first)
@@ -841,14 +841,14 @@ end
841841

842842
function delete_models(ctx::Context, database::AbstractString, engine::AbstractString, models::Vector{String}; kw...)
843843
queries = ["""
844-
def delete:rel:catalog:model[$(_escape_string_for_rel(model))] = rel:catalog:model[$(_escape_string_for_rel(model))]
844+
def delete[:rel, :catalog, :model, $(_escape_string_for_rel(model))]: rel[:catalog, :model, $(_escape_string_for_rel(model))]
845845
""" for model in models]
846846
return exec(ctx, database, engine, join(queries, "\n"); readonly=false, kw...)
847847
end
848848

849849
function delete_models_async(ctx::Context, database::AbstractString, engine::AbstractString, model::AbstractString; kw...)
850850
queries = ["""
851-
def delete:rel:catalog:model[$(_escape_string_for_rel(model))] = rel:catalog:model[$(_escape_string_for_rel(model))
851+
def delete[:rel, :catalog, :model, $(_escape_string_for_rel(model))]: rel[:catalog, :model, $(_escape_string_for_rel(model))]
852852
""" for model in models]
853853
return exec_async(ctx, database, engine, join(queries, "\n"); readonly=false, kw...)
854854
end

0 commit comments

Comments
 (0)