@@ -234,11 +234,8 @@ function delete_engine(ctx::Context, engine::AbstractString; kw...)
234234 return _delete (ctx, PATH_ENGINE; body = JSON3. write (data), kw... )
235235end
236236
237- function delete_model (ctx:: Context , database:: AbstractString , engine:: AbstractString , model:: AbstractString ; kw... )
238- tx = Transaction (ctx. region, database, engine, " OPEN" ; readonly = false )
239- actions = [_make_delete_models_action ([model])]
240- return _post (ctx, PATH_TRANSACTION; query = query (tx), body = body (tx, actions... ), kw... )
241- end
237+ # escape rel special string
238+ _escape_string_for_rel (str) = replace (repr (str), ' %' => " \\ %" )
242239
243240function delete_oauth_client (ctx:: Context , id:: AbstractString ; kw... )
244241 return _delete (ctx, joinpath (PATH_OAUTH_CLIENTS, id); kw... )
@@ -270,15 +267,6 @@ function get_database(ctx::Context, database::AbstractString; kw...)
270267 return rsp[1 ]
271268end
272269
273- # todo: move to rel query
274- function get_model (ctx:: Context , database:: AbstractString , engine:: AbstractString , name:: AbstractString ; kw... )
275- models = _list_models (ctx, database, engine; kw... )
276- for model in models
277- model[" name" ] == name && return model[" value" ]
278- end
279- throw (HTTPError (404 ))
280- end
281-
282270function get_oauth_client (ctx:: Context , id:: AbstractString ; kw... )
283271 return _get (ctx, joinpath (PATH_OAUTH_CLIENTS, id); kw... ). client
284272end
@@ -387,22 +375,6 @@ function _make_actions(actions...)
387375 return result
388376end
389377
390- function _make_delete_models_action (models:: Vector )
391- return Dict (
392- " type" => " ModifyWorkspaceAction" ,
393- " delete_source" => models)
394- end
395-
396- function _make_load_model_action (name, model)
397- return Dict (
398- " type" => " InstallAction" ,
399- " sources" => [_make_query_source (name, model)])
400- end
401-
402- function _make_list_models_action ()
403- return Dict (" type" => " ListSourceAction" )
404- end
405-
406378function _make_list_edb_action ()
407379 return Dict (" type" => " ListEdbAction" )
408380end
@@ -695,19 +667,6 @@ function list_edbs(ctx::Context, database::AbstractString, engine::AbstractStrin
695667 return rsp. actions[1 ]. result. rels
696668end
697669
698- function _list_models (ctx:: Context , database:: AbstractString , engine:: AbstractString ; kw... )
699- tx = Transaction (ctx. region, database, engine, " OPEN" ; readonly = true )
700- data = body (tx, _make_list_models_action ())
701- rsp = _post (ctx, PATH_TRANSACTION; query = query (tx), body = data, kw... ). actions
702- length (rsp) == 0 && return []
703- return rsp[1 ]. result. sources
704- end
705-
706- function list_models (ctx:: Context , database:: AbstractString , engine:: AbstractString ; kw... )
707- models = _list_models (ctx, database, engine; kw... )
708- return [model[" name" ] for model in models]
709- end
710-
711670function _gen_literal (value)
712671 return " $value "
713672end
@@ -777,13 +736,82 @@ function load_json(ctx::Context, database::AbstractString, engine::AbstractStrin
777736 return exec (ctx, database, engine, source; inputs = inputs, readonly = false , kw... )
778737end
779738
780- function load_model (ctx:: Context , database:: AbstractString , engine:: AbstractString , models:: Dict ; kw... )
781- tx = Transaction (ctx. region, database, engine, " OPEN" ; readonly = false )
782- actions = [_make_load_model_action (name, model) for (name, model) in models]
783- return _post (ctx, PATH_TRANSACTION; query = query (tx), body = body (tx, actions... ), kw... )
739+ function load_models (ctx:: Context , database:: AbstractString , engine:: AbstractString , models:: Dict ; kw... )
740+ queries = []
741+ queries_inputs = Dict ()
742+ rand_uint = rand (UInt64)
743+
744+ index = 0
745+ for (name, value) in models
746+ input_name = string (" input_" , rand_uint, " _" , index)
747+ push! (queries, """
748+ def delete:rel:catalog:model["$name "] = rel:catalog:model["$name "]
749+ def insert:rel:catalog:model["$name "] = $input_name
750+ """ )
751+
752+ queries_inputs[input_name] = value
753+ index+= 1
754+ end
755+
756+ return exec (ctx, database, engine, join (queries, " \n " ); inputs = queries_inputs, readonly = false , kw... )
784757end
785758
759+ function load_models_async (ctx:: Context , database:: AbstractString , engine:: AbstractString , models:: Dict ; kw... )
760+ queries = []
761+ queries_inputs = Dict ()
762+ rand_uint = rand (UInt64)
763+
764+ index = 0
765+ for (name, value) in models
766+ input_name = string (" input_" , rand_uint, " _" , index)
767+ push! (queries, """
768+ def delete:rel:catalog:model["$name "] = rel:catalog:model["$name "]
769+ def insert:rel:catalog:model["$name "] = $input_name
770+ """ )
786771
772+ queries_inputs[input_name] = value
773+ index+= 1
774+ end
775+
776+ return exec_async (ctx, database, engine, join (queries, " \n " ); inputs = queries_inputs, readonly = false , kw... )
777+ end
778+
779+ function list_models (ctx:: Context , database:: AbstractString , engine:: AbstractString ; kw... )
780+ out_name = " model$(rand (UInt64)) "
781+ query = """ def output:$out_name [name] = rel:catalog:model(name, _) """
782+ resp = exec (ctx, database, engine, query)
783+ for result in resp. results
784+ if occursin (" /:output/:$out_name " , result. first)
785+ return [name for name in result. second. v1]
786+ end
787+ end
788+ end
789+
790+ function get_model (ctx:: Context , database:: AbstractString , engine:: AbstractString , name:: AbstractString ; kw... )
791+ out_name = " model$(rand (UInt64)) "
792+ query = """ def output:$out_name = rel:catalog:model[$(_escape_string_for_rel (name)) ]"""
793+ resp = exec (ctx, database, engine, query)
794+ for result in resp. results
795+ if occursin (" /:output/:$out_name " , result. first)
796+ return first (result. second. v1)
797+ end
798+ end
799+ throw (HTTPError (404 ))
800+ end
801+
802+ function delete_models (ctx:: Context , database:: AbstractString , engine:: AbstractString , models:: Vector{String} ; kw... )
803+ queries = ["""
804+ def delete:rel:catalog:model[$(_escape_string_for_rel (model)) ] = rel:catalog:model[$(_escape_string_for_rel (model)) ]
805+ """ for model in models]
806+ return exec (ctx, database, engine, join (queries, " \n " ); readonly= false , kw... )
807+ end
808+
809+ function delete_models_async (ctx:: Context , database:: AbstractString , engine:: AbstractString , model:: AbstractString ; kw... )
810+ queries = ["""
811+ def delete:rel:catalog:model[$(_escape_string_for_rel (model)) ] = rel:catalog:model[$(_escape_string_for_rel (model))
812+ """ for model in models]
813+ return exec_async (ctx, database, engine, join (queries, " \n " ); readonly= false , kw... )
814+ end
787815
788816# --- utils -------------------------
789817# Patch for older versions of HTTP package that don't support parsing multipart responses:
0 commit comments