kura_query_compiler (kura v2.0.6)

View Source

Public entry point for compiling kura_query ASTs into SQL.

Resolves the dialect per repo: the configured dialect module lives in the repo's config map (set automatically when the repo declares a {backend, ...}). Different repos in the same app may use different dialects.

This module is internal. Use kura_repo_worker for executing queries.

Summary

Functions

delete(RepoMod, SchemaOrTable, PKField, PKValue)

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

delete_all(RepoMod, Query)

-spec delete_all(module(),
                 #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()]}.

dialect(RepoMod)

-spec dialect(module()) -> module().

Return the dialect module configured for RepoMod.

Resolution order:

  1. dialect key in the repo's config map (multi-repo or v2.4 flat env).
  2. Global application:get_env(kura, dialect) for legacy single-dialect setups.

insert(RepoMod, SchemaOrTable, Fields, Data)

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

insert(RepoMod, SchemaOrTable, Fields, Data, Opts)

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

insert_all(RepoMod, SchemaOrTable, Fields, Rows)

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

insert_all(RepoMod, SchemaOrTable, Fields, Rows, Opts)

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

to_sql(RepoMod, Query)

-spec to_sql(module(),
             #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} for RepoMod's dialect.

to_sql_cached(RepoMod, Query)

-spec to_sql_cached(module(),
                    #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()]}.

Cached to_sql/2. The cache key includes RepoMod so two repos with different dialects don't share an entry.

to_sql_from(RepoMod, Query, StartCounter)

-spec to_sql_from(module(),
                  #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()}.

update(RepoMod, SchemaOrTable, Fields, Changes, PK)

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

update_all(RepoMod, Query, SetMap)

-spec update_all(module(),
                 #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()]}.