kura_ets_dialect (kura_ets v0.0.1)

View Source

"Dialect" for the ETS backend. There is no SQL to emit: each callback wraps the portable #kura_query{} AST (or the operation data) into an opaque {kura_ets, Plan} term that kura_ets_driver hands to kura_ets_query for interpretation against ETS tables.

The parameter list is always []: values stay embedded in the plan. This keeps the plan a pure function of the query AST, so kura's query cache (kura_query_compiler:to_sql_cached/2, keyed on the hashed AST) remains correct.

One observable difference vs SQL dialects: kura's query telemetry and legacy logging stringify the compiled statement with iolist_to_binary/1, which does not accept a plan tuple; those events are skipped for this backend (kura wraps emission in a catch).

Summary

Types

plan()

-type plan() ::
          {select,
           #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()}} |
          {insert, atom() | module(), map(), map()} |
          {update, atom() | module(), map(), [{atom(), term()}]} |
          {delete, atom() | module(), [{atom(), term()}]} |
          {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()} |
          {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()}} |
          {insert_all, atom() | module(), [map()], map()}.

Functions

delete(SchemaOrTable, KeyClauses)

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

delete_all(Query)

-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()}) ->
                    {dynamic(), [term()]}.

insert(SchemaOrTable, Fields, Data)

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

insert(SchemaOrTable, Fields, Data, Opts)

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

insert_all(SchemaOrTable, Fields, Rows)

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

insert_all(SchemaOrTable, Fields, Rows, Opts)

-spec insert_all(atom() | module(), [atom()], [map()], map()) -> {dynamic(), [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()}) ->
                {dynamic(), [term()]}.

to_sql_from(Query, StartCounter)

-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()) ->
                     {dynamic(), [term()], pos_integer()}.

update(SchemaOrTable, Fields, Changes, KeyClauses)

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

update_all(Query, SetMap)

-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()) ->
                    {dynamic(), [term()]}.