-module(based). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([register/3, new_query/1, with_args/2, with_decoder/2, exec/2, all/2, one/2, string/1, int/1, float/1, bool/1, null/0]). -export_type([value/0, 'query'/1, returned/1, db/2]). -type value() :: {string, binary()} | {int, integer()} | {float, float()} | {bool, boolean()} | null. -type 'query'(FQU) :: {'query', binary(), list(value()), gleam@option:option(fun((gleam@dynamic:dynamic_()) -> {ok, FQU} | {error, list(gleam@dynamic:decode_error())}))}. -type returned(FQV) :: {returned, integer(), list(FQV)}. -type db(FQW, FQX) :: {db, FQX, fun(('query'(FQW), FQX) -> {ok, returned(FQW)} | {error, nil})}. -spec register( fun((FRQ, fun((db(FRP, FRR)) -> {ok, returned(FRP)} | {error, nil})) -> {ok, returned(FRP)} | {error, nil}), FRQ, fun((db(FRP, FRR)) -> {ok, returned(FRP)} | {error, nil}) ) -> {ok, returned(FRP)} | {error, nil}. register(With_connection, B, Callback) -> With_connection(B, Callback). -spec new_query(binary()) -> 'query'(any()). new_query(Sql) -> {'query', Sql, [], none}. -spec with_args('query'(FSF), list(value())) -> 'query'(FSF). with_args(Query, Args) -> erlang:setelement(3, Query, Args). -spec with_decoder( 'query'(FSJ), fun((gleam@dynamic:dynamic_()) -> {ok, FSJ} | {error, list(gleam@dynamic:decode_error())}) ) -> 'query'(FSJ). with_decoder(Query, Decoder) -> erlang:setelement(4, Query, {some, Decoder}). -spec exec('query'(FTC), db(FTC, any())) -> {ok, returned(FTC)} | {error, nil}. exec(Query, Db) -> _pipe = Query, (erlang:element(3, Db))(_pipe, erlang:element(2, Db)). -spec all('query'(FSN), db(FSN, any())) -> {ok, returned(FSN)} | {error, nil}. all(Query, Db) -> exec(Query, Db). -spec one('query'(FSV), db(FSV, any())) -> {ok, FSV} | {error, nil}. one(Query, Db) -> gleam@result:'try'( exec(Query, Db), fun(Returned) -> {returned, _, Rows} = Returned, gleam@result:'try'( begin _pipe = Rows, gleam@list:first(_pipe) end, fun(Row) -> {ok, Row} end ) end ). -spec string(binary()) -> value(). string(Value) -> {string, Value}. -spec int(integer()) -> value(). int(Value) -> {int, Value}. -spec float(float()) -> value(). float(Value) -> {float, Value}. -spec bool(boolean()) -> value(). bool(Value) -> {bool, Value}. -spec null() -> value(). null() -> null.