kura_dialect_pg (kura v2.0.6)

View Source

PostgreSQL dialect. Translates a #kura_query{} AST into parameterized SQL using pgo's $N placeholder convention.

This module is an implementation of kura_dialect. Public callers go through kura_query_compiler, which delegates to the dialect configured for the running app.

Summary

Functions

Compile a query record into {SQL, Params}.

Compile a query starting parameter numbering from StartCounter. Returns {SQL, Params, NextCounter}.

Functions

column_type(Type)

-spec column_type(kura_types:kura_type()) -> binary().

delete(SchemaOrTable, PKField, PKValue)

-spec delete(atom() | module(), atom(), term()) -> {iodata(), [term()]}.

delete_all/1

-spec delete_all(#kura_query{from :: atom() | module() | undefined,
                             select :: [atom() | term()] | {exprs, [term()]},
                             wheres :: [term()],
                             joins :: [term()],
                             order_bys :: [term()],
                             group_bys :: [atom()],
                             havings :: [term()],
                             limit :: non_neg_integer() | undefined,
                             offset :: non_neg_integer() | undefined,
                             distinct :: boolean() | [atom()],
                             lock :: binary() | undefined,
                             prefix :: binary() | undefined,
                             preloads :: [atom() | {atom(), list()}],
                             ctes :: [{binary(), #kura_query{}}],
                             combinations :: [{union | union_all | intersect | except, #kura_query{}}],
                             include_deleted :: boolean()}) ->
                    {iodata(), [term()]}.

format_default/1

-spec format_default(term()) -> binary().

insert(SchemaOrTable, Fields, Data)

-spec insert(atom() | module(), [atom()], map()) -> {iodata(), [term()]}.

insert/4

-spec insert(atom() | module(), [atom()], map(), map()) -> {iodata(), [term()]}.

insert_all(SchemaOrTable, Fields, Rows)

-spec insert_all(atom() | module(), [atom()], [map()]) -> {iodata(), [term()]}.

insert_all/4

-spec insert_all(atom() | module(), [atom()], [map()], map()) -> {iodata(), [term()]}.

to_sql(Query)

-spec to_sql(#kura_query{from :: atom() | module() | undefined,
                         select :: [atom() | term()] | {exprs, [term()]},
                         wheres :: [term()],
                         joins :: [term()],
                         order_bys :: [term()],
                         group_bys :: [atom()],
                         havings :: [term()],
                         limit :: non_neg_integer() | undefined,
                         offset :: non_neg_integer() | undefined,
                         distinct :: boolean() | [atom()],
                         lock :: binary() | undefined,
                         prefix :: binary() | undefined,
                         preloads :: [atom() | {atom(), list()}],
                         ctes :: [{binary(), #kura_query{}}],
                         combinations :: [{union | union_all | intersect | except, #kura_query{}}],
                         include_deleted :: boolean()}) ->
                {iodata(), [term()]}.

Compile a query record into {SQL, Params}.

to_sql_from/2

-spec to_sql_from(#kura_query{from :: atom() | module() | undefined,
                              select :: [atom() | term()] | {exprs, [term()]},
                              wheres :: [term()],
                              joins :: [term()],
                              order_bys :: [term()],
                              group_bys :: [atom()],
                              havings :: [term()],
                              limit :: non_neg_integer() | undefined,
                              offset :: non_neg_integer() | undefined,
                              distinct :: boolean() | [atom()],
                              lock :: binary() | undefined,
                              prefix :: binary() | undefined,
                              preloads :: [atom() | {atom(), list()}],
                              ctes :: [{binary(), #kura_query{}}],
                              combinations :: [{union | union_all | intersect | except, #kura_query{}}],
                              include_deleted :: boolean()},
                  pos_integer()) ->
                     {iodata(), [term()], pos_integer()}.

Compile a query starting parameter numbering from StartCounter. Returns {SQL, Params, NextCounter}.

update/4

-spec update(atom() | module(), [atom()], map(), {atom(), term()}) -> {iodata(), [term()]}.

update_all/2

-spec update_all(#kura_query{from :: atom() | module() | undefined,
                             select :: [atom() | term()] | {exprs, [term()]},
                             wheres :: [term()],
                             joins :: [term()],
                             order_bys :: [term()],
                             group_bys :: [atom()],
                             havings :: [term()],
                             limit :: non_neg_integer() | undefined,
                             offset :: non_neg_integer() | undefined,
                             distinct :: boolean() | [atom()],
                             lock :: binary() | undefined,
                             prefix :: binary() | undefined,
                             preloads :: [atom() | {atom(), list()}],
                             ctes :: [{binary(), #kura_query{}}],
                             combinations :: [{union | union_all | intersect | except, #kura_query{}}],
                             include_deleted :: boolean()},
                 map()) ->
                    {iodata(), [term()]}.