Current section
Files
Jump to
Current section
Files
src/parrot@internal@sqlc.erl
-module(parrot@internal@sqlc).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([decode_sqlc/1]).
-export_type([type_ref/0, table_column/0, table_ref/0, table/0, schema/0, catalog/0, query_cmd/0, query_param/0, 'query'/0, sqlc/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-type type_ref() :: {type_ref, binary(), binary(), binary()}.
-type table_column() :: {table_column,
binary(),
boolean(),
boolean(),
binary(),
integer(),
boolean(),
boolean(),
binary(),
binary(),
boolean(),
binary(),
boolean(),
integer(),
gleam@option:option(table_ref()),
type_ref()}.
-type table_ref() :: {table_ref, binary(), binary(), binary()}.
-type table() :: {table, table_ref(), binary(), list(table_column())}.
-type schema() :: {schema, binary(), binary(), list(table())}.
-type catalog() :: {catalog, binary(), binary(), binary(), list(schema())}.
-type query_cmd() :: one | many | exec | exec_result.
-type query_param() :: {query_param, integer(), table_column()}.
-type 'query'() :: {'query',
binary(),
binary(),
query_cmd(),
binary(),
list(table_column()),
gleam@option:option(table_ref()),
list(binary()),
list(query_param())}.
-type sqlc() :: {sqlc, binary(), binary(), binary(), catalog(), list('query'())}.
-file("src/parrot/internal/sqlc.gleam", 87).
?DOC(false).
-spec decode_sqlc(gleam@dynamic:dynamic_()) -> {ok, sqlc()} |
{error, list(gleam@dynamic:decode_error())}.
decode_sqlc(Data) ->
Table_ref_decoder = begin
_pipe = decode:into(
begin
decode:parameter(
fun(Catalog) ->
decode:parameter(
fun(Schema) ->
decode:parameter(
fun(Name) ->
{table_ref, Catalog, Schema, Name}
end
)
end
)
end
)
end
),
_pipe@1 = decode:field(
_pipe,
<<"catalog"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@2 = decode:field(
_pipe@1,
<<"schema"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
decode:field(
_pipe@2,
<<"name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
)
end,
Type_ref_decoder = begin
_pipe@3 = decode:into(
begin
decode:parameter(
fun(Catalog@1) ->
decode:parameter(
fun(Schema@1) ->
decode:parameter(
fun(Name@1) ->
{type_ref, Catalog@1, Schema@1, Name@1}
end
)
end
)
end
)
end
),
_pipe@4 = decode:field(
_pipe@3,
<<"catalog"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@5 = decode:field(
_pipe@4,
<<"schema"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
decode:field(
_pipe@5,
<<"name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
)
end,
Table_col_decoder = begin
_pipe@6 = decode:into(
begin
decode:parameter(
fun(Name@2) ->
decode:parameter(
fun(Not_null) ->
decode:parameter(
fun(Is_array) ->
decode:parameter(
fun(Comment) ->
decode:parameter(
fun(Length) ->
decode:parameter(
fun(Is_named_param) ->
decode:parameter(
fun(
Is_func_call
) ->
decode:parameter(
fun(
Scope
) ->
decode:parameter(
fun(
Table_alias
) ->
decode:parameter(
fun(
Is_sqlc_slice
) ->
decode:parameter(
fun(
Original_name
) ->
decode:parameter(
fun(
Unsigned
) ->
decode:parameter(
fun(
Array_dims
) ->
decode:parameter(
fun(
Table
) ->
decode:parameter(
fun(
Type_ref
) ->
{table_column,
Name@2,
Not_null,
Is_array,
Comment,
Length,
Is_named_param,
Is_func_call,
Scope,
Table_alias,
Is_sqlc_slice,
Original_name,
Unsigned,
Array_dims,
Table,
Type_ref}
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
),
_pipe@7 = decode:field(
_pipe@6,
<<"name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@8 = decode:field(
_pipe@7,
<<"not_null"/utf8>>,
{decoder, fun gleam@dynamic:bool/1}
),
_pipe@9 = decode:field(
_pipe@8,
<<"is_array"/utf8>>,
{decoder, fun gleam@dynamic:bool/1}
),
_pipe@10 = decode:field(
_pipe@9,
<<"comment"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@11 = decode:field(
_pipe@10,
<<"length"/utf8>>,
{decoder, fun gleam@dynamic:int/1}
),
_pipe@12 = decode:field(
_pipe@11,
<<"is_named_param"/utf8>>,
{decoder, fun gleam@dynamic:bool/1}
),
_pipe@13 = decode:field(
_pipe@12,
<<"is_func_call"/utf8>>,
{decoder, fun gleam@dynamic:bool/1}
),
_pipe@14 = decode:field(
_pipe@13,
<<"scope"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@15 = decode:field(
_pipe@14,
<<"table_alias"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@16 = decode:field(
_pipe@15,
<<"is_sqlc_slice"/utf8>>,
{decoder, fun gleam@dynamic:bool/1}
),
_pipe@17 = decode:field(
_pipe@16,
<<"original_name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@18 = decode:field(
_pipe@17,
<<"unsigned"/utf8>>,
{decoder, fun gleam@dynamic:bool/1}
),
_pipe@19 = decode:field(
_pipe@18,
<<"array_dims"/utf8>>,
{decoder, fun gleam@dynamic:int/1}
),
_pipe@20 = decode:field(
_pipe@19,
<<"table"/utf8>>,
decode:optional(Table_ref_decoder)
),
decode:field(_pipe@20, <<"type"/utf8>>, Type_ref_decoder)
end,
Table_decoder = begin
_pipe@21 = decode:into(
begin
decode:parameter(
fun(Rel) ->
decode:parameter(
fun(Comment@1) ->
decode:parameter(
fun(Columns) ->
{table, Rel, Comment@1, Columns}
end
)
end
)
end
)
end
),
_pipe@22 = decode:field(_pipe@21, <<"rel"/utf8>>, Table_ref_decoder),
_pipe@23 = decode:field(
_pipe@22,
<<"comment"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
decode:field(
_pipe@23,
<<"columns"/utf8>>,
decode:list(Table_col_decoder)
)
end,
Schema_decoder = begin
_pipe@24 = decode:into(
begin
decode:parameter(
fun(Comment@2) ->
decode:parameter(
fun(Name@3) ->
decode:parameter(
fun(Tables) ->
{schema, Comment@2, Name@3, Tables}
end
)
end
)
end
)
end
),
_pipe@25 = decode:field(
_pipe@24,
<<"comment"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@26 = decode:field(
_pipe@25,
<<"name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
decode:field(_pipe@26, <<"tables"/utf8>>, decode:list(Table_decoder))
end,
Catalog_decoder = begin
_pipe@27 = decode:into(
begin
decode:parameter(
fun(Comment@3) ->
decode:parameter(
fun(Default_schema) ->
decode:parameter(
fun(Name@4) ->
decode:parameter(
fun(Schemas) ->
{catalog,
Comment@3,
Default_schema,
Name@4,
Schemas}
end
)
end
)
end
)
end
)
end
),
_pipe@28 = decode:field(
_pipe@27,
<<"comment"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@29 = decode:field(
_pipe@28,
<<"default_schema"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@30 = decode:field(
_pipe@29,
<<"name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
decode:field(_pipe@30, <<"schemas"/utf8>>, decode:list(Schema_decoder))
end,
Params_decoder = begin
_pipe@31 = decode:into(
begin
decode:parameter(
fun(Number) ->
decode:parameter(
fun(Column) -> {query_param, Number, Column} end
)
end
)
end
),
_pipe@32 = decode:field(
_pipe@31,
<<"number"/utf8>>,
{decoder, fun gleam@dynamic:int/1}
),
decode:field(_pipe@32, <<"column"/utf8>>, Table_col_decoder)
end,
Cmd_decoder = begin
_pipe@33 = {decoder, fun gleam@dynamic:string/1},
decode:then(_pipe@33, fun(Cmd) -> case Cmd of
<<":one"/utf8>> ->
decode:into(one);
<<":many"/utf8>> ->
decode:into(many);
<<":exec"/utf8>> ->
decode:into(exec_result);
<<":execresult"/utf8>> ->
decode:into(exec_result);
_ ->
decode:fail(<<"QueryCmd"/utf8>>)
end end)
end,
Query_decoder = begin
_pipe@34 = decode:into(
begin
decode:parameter(
fun(Text) ->
decode:parameter(
fun(Name@5) ->
decode:parameter(
fun(Cmd@1) ->
decode:parameter(
fun(Filename) ->
decode:parameter(
fun(Columns@1) ->
decode:parameter(
fun(
Insert_into_table
) ->
decode:parameter(
fun(
Comments
) ->
decode:parameter(
fun(
Params
) ->
{'query',
Text,
Name@5,
Cmd@1,
Filename,
Columns@1,
Insert_into_table,
Comments,
Params}
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
),
_pipe@35 = decode:field(
_pipe@34,
<<"text"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@36 = decode:field(
_pipe@35,
<<"name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@37 = decode:field(_pipe@36, <<"cmd"/utf8>>, Cmd_decoder),
_pipe@38 = decode:field(
_pipe@37,
<<"filename"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@39 = decode:field(
_pipe@38,
<<"columns"/utf8>>,
decode:list(Table_col_decoder)
),
_pipe@40 = decode:field(
_pipe@39,
<<"insert_into_table"/utf8>>,
decode:optional(Table_ref_decoder)
),
_pipe@41 = decode:field(
_pipe@40,
<<"comments"/utf8>>,
decode:list({decoder, fun gleam@dynamic:string/1})
),
decode:field(_pipe@41, <<"params"/utf8>>, decode:list(Params_decoder))
end,
Decoder = begin
_pipe@42 = decode:into(
begin
decode:parameter(
fun(Sqlc_version) ->
decode:parameter(
fun(Plugin_options) ->
decode:parameter(
fun(Global_options) ->
decode:parameter(
fun(Catalog@2) ->
decode:parameter(
fun(Queries) ->
{sqlc,
Sqlc_version,
Plugin_options,
Global_options,
Catalog@2,
Queries}
end
)
end
)
end
)
end
)
end
)
end
),
_pipe@43 = decode:field(
_pipe@42,
<<"sqlc_version"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@44 = decode:field(
_pipe@43,
<<"plugin_options"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@45 = decode:field(
_pipe@44,
<<"global_options"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@46 = decode:field(_pipe@45, <<"catalog"/utf8>>, Catalog_decoder),
decode:field(_pipe@46, <<"queries"/utf8>>, decode:list(Query_decoder))
end,
decode:from(Decoder, Data).