-module(cake@adapter@sqlite_adapter). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([with_memory_connection/1, execute/2, to_prepared_statement/1, run_query/3]). -spec with_memory_connection(fun((sqlight:connection()) -> OGD)) -> OGD. with_memory_connection(Callback_fun) -> sqlight:with_connection(<<":memory:"/utf8>>, Callback_fun). -spec execute(binary(), sqlight:connection()) -> {ok, nil} | {error, sqlight:error()}. execute(Query, Conn) -> _pipe = Query, sqlight:exec(_pipe, Conn). -spec to_prepared_statement(cake@internal@query:'query'()) -> cake@internal@prepared_statement:prepared_statement(). to_prepared_statement(Qry) -> _pipe = Qry, cake@internal@query:builder_new(_pipe, <<"?"/utf8>>). -spec run_query( sqlight:connection(), cake@internal@query:'query'(), fun((gleam@dynamic:dynamic_()) -> {ok, OGM} | {error, list(gleam@dynamic:decode_error())}) ) -> {ok, list(OGM)} | {error, sqlight:error()}. run_query(Db_conn, Qry, Dcdr) -> Prp_stm = to_prepared_statement(Qry), Sql = begin _pipe = cake@internal@prepared_statement:get_sql(Prp_stm), cake@stdlib@iox:dbg(_pipe) end, Params = cake@internal@prepared_statement:get_params(Prp_stm), Db_params = begin _pipe@1 = Params, _pipe@2 = gleam@list:map(_pipe@1, fun(Param) -> case Param of {bool_param, Param@1} -> sqlight:bool(Param@1); {float_param, Param@2} -> sqlight:float(Param@2); {int_param, Param@3} -> sqlight:int(Param@3); {string_param, Param@4} -> sqlight:text(Param@4) end end), _pipe@3 = cake@stdlib@iox:print_tap(_pipe@2, <<"Params: "/utf8>>), cake@stdlib@iox:dbg(_pipe@3) end, _pipe@4 = Sql, sqlight:'query'(_pipe@4, Db_conn, Db_params, Dcdr).