kura_query (kura v1.19.2)

View Source

Composable, functional query builder.

Build queries by piping through from/1, where/2, select/2, order_by/2, etc. Queries are compiled to parameterized SQL by kura_query_compiler.

Q = kura_query:from(my_user),
Q1 = kura_query:where(Q, {active, true}),
Q2 = kura_query:order_by(Q1, [{name, asc}]),
Q3 = kura_query:limit(Q2, 10).

Summary

Functions

Set query to SELECT COUNT(*).

Combine queries with EXCEPT.

Start a query from the given schema module or table atom.

Combine queries with INTERSECT.

Add a JOIN clause. Table can be a schema module or raw table atom. On is {LeftCol, RightCol} where LeftCol is on the previous table (FROM for the first join, or the last joined table) and RightCol is on the joined table. For chained joins, the left side automatically advances.

Return only soft-deleted records.

Set ORDER BY clauses as [{field, asc | desc}].

Add associations to preload after query execution.

Apply a composable query transform function.

Set the SELECT fields. Pass atoms for columns or {agg, field} tuples for aggregates.

Set raw SQL expressions in SELECT with aliases. Exprs = [{Alias, {fragment, SQL, Params}}].

Combine queries with UNION (removes duplicates).

Combine queries with UNION ALL (keeps duplicates).

Add a WHERE condition. Conditions: {field, value}, {field, op, value}, {'and', [...]}, etc.

Add a Common Table Expression (WITH clause).

Include soft-deleted records in query results.

Functions

avg(Q, Field)

-spec avg(#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()},
          atom()) ->
             #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()}.

count(Q)

-spec count(#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()}) ->
               #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()}.

Set query to SELECT COUNT(*).

count(Q, Field)

-spec count(#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()},
            atom()) ->
               #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()}.

distinct(Q)

-spec distinct(#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()}) ->
                  #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()}.

distinct(Q, Fields)

-spec distinct(#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()},
               [atom()]) ->
                  #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()}.

except/2

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

Combine queries with EXCEPT.

from(Source)

-spec from(atom() | 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()}.

Start a query from the given schema module or table atom.

group_by(Q, Fields)

-spec group_by(#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()},
               [atom()]) ->
                  #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()}.

having/2

-spec having(#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()},
             term()) ->
                #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()}.

intersect/2

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

Combine queries with INTERSECT.

join(Q, Type, Table, On)

-spec join(#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()},
           inner | left | right | full,
           atom(),
           {atom(), atom()}) ->
              #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()}.

Add a JOIN clause. Table can be a schema module or raw table atom. On is {LeftCol, RightCol} where LeftCol is on the previous table (FROM for the first join, or the last joined table) and RightCol is on the joined table. For chained joins, the left side automatically advances.

Q = kura_query:from(user_schema),
Q1 = kura_query:join(Q, inner, post_schema, {id, user_id}),
%% => users.id = posts.user_id
Q2 = kura_query:join(Q1, inner, comment_schema, {id, post_id}).
%% => posts.id = comments.post_id

join/5

-spec join(#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()},
           inner | left | right | full,
           atom(),
           {atom(), atom()},
           atom() | undefined) ->
              #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()}.

limit(Q, N)

-spec limit(#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()},
            non_neg_integer()) ->
               #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()}.

lock(Q, LockExpr)

-spec lock(#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()},
           binary()) ->
              #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()}.

max(Q, Field)

-spec max(#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()},
          atom()) ->
             #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()}.

min(Q, Field)

-spec min(#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()},
          atom()) ->
             #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()}.

offset(Q, N)

-spec offset(#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()},
             non_neg_integer()) ->
                #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()}.

only_deleted(Q)

-spec only_deleted(#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()}) ->
                      #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()}.

Return only soft-deleted records.

order_by(Q, Orders)

-spec order_by(#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()},
               [{atom(), asc | desc}]) ->
                  #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()}.

Set ORDER BY clauses as [{field, asc | desc}].

prefix(Q, Schema)

-spec prefix(#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()},
             binary()) ->
                #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()}.

preload/2

-spec preload(#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()},
              [atom() | {atom(), list()}]) ->
                 #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()}.

Add associations to preload after query execution.

scope(Query, Fun)

-spec scope(#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()},
            fun((#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()}) ->
                    #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()})) ->
               #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()}.

Apply a composable query transform function.

select(Q, Fields)

-spec 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()},
             [atom() | term()]) ->
                #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()}.

Set the SELECT fields. Pass atoms for columns or {agg, field} tuples for aggregates.

select_expr(Q, Exprs)

-spec select_expr(#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()},
                  [term()]) ->
                     #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()}.

Set raw SQL expressions in SELECT with aliases. Exprs = [{Alias, {fragment, SQL, Params}}].

sum(Q, Field)

-spec sum(#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()},
          atom()) ->
             #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()}.

union/2

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

Combine queries with UNION (removes duplicates).

union_all/2

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

Combine queries with UNION ALL (keeps duplicates).

where/2

-spec where(#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()},
            term()) ->
               #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()}.

Add a WHERE condition. Conditions: {field, value}, {field, op, value}, {'and', [...]}, etc.

with_cte/3

-spec with_cte(#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()},
               binary(),
               #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()}) ->
                  #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()}.

Add a Common Table Expression (WITH clause).

with_deleted(Q)

-spec with_deleted(#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()}) ->
                      #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()}.

Include soft-deleted records in query results.