All files / src/sql ast-statements.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105                                                                                                                                                                                                                 
import type { ExprNode, OrderNode } from './ast-expressions.ts';
import type {
  FromItem,
  JoinNode,
  LockNode,
  MergeWhen,
  OnConflictNode,
  SetOperationNode,
  SetItem,
  TableRef,
  WithClause,
} from './ast-clauses.ts';
 
export type SelectNode = Readonly<{
  kind: 'select';
  with?: WithClause;
  extraFrom?: readonly FromItem[];
  distinct?: boolean;
  distinctOn?: readonly ExprNode[];
  columns: readonly ExprNode[];
  from: FromItem;
  joins?: readonly JoinNode[];
  where?: ExprNode;
  groupBy?: readonly ExprNode[];
  having?: ExprNode;
  orderBy?: readonly OrderNode[];
  limit?: number;
  /** `FETCH FIRST n ROWS WITH TIES` instead of `LIMIT n`; needs `limit` and `orderBy`. */
  withTies?: boolean;
  offset?: number;
  lock?: LockNode;
}>;
 
/** A query expression: a SELECT or a set operation over query expressions. */
export type QueryNode = SelectNode | SetOperationNode;
 
export type InsertNode = Readonly<{
  kind: 'insert';
  table: TableRef;
  columns: readonly string[];
  rows: readonly (readonly ExprNode[])[];
  select?: QueryNode;
  overriding?: 'system' | 'user';
  onConflict?: OnConflictNode;
  returning?: readonly ExprNode[];
  /** Alias of the pre-statement row in RETURNING (`WITH (OLD AS ...)`, PostgreSQL 18+). */
  returningOld?: string;
}>;
 
export type UpdateNode = Readonly<{
  kind: 'update';
  table: TableRef;
  set: readonly SetItem[];
  from?: readonly FromItem[];
  where?: ExprNode;
  returning?: readonly ExprNode[];
  /** Alias of the pre-statement row in RETURNING (`WITH (OLD AS ...)`, PostgreSQL 18+). */
  returningOld?: string;
}>;
 
export type DeleteNode = Readonly<{
  kind: 'delete';
  table: TableRef;
  using?: readonly FromItem[];
  where?: ExprNode;
  returning?: readonly ExprNode[];
}>;
 
export type TruncateNode = Readonly<{
  kind: 'truncate';
  table: TableRef;
  cascade?: boolean;
  restartIdentity?: boolean;
}>;
 
export type MergeNode = Readonly<{
  kind: 'merge';
  table: TableRef;
  source:
    | Readonly<{ kind: 'query'; query: QueryNode; alias: string }>
    | Readonly<{
        kind: 'values';
        columns: readonly string[];
        rows: readonly (readonly ExprNode[])[];
        alias: string;
      }>;
  on: ExprNode;
  when: readonly MergeWhen[];
  returning?: readonly ExprNode[];
  /** Alias of the pre-statement row in RETURNING (`WITH (OLD AS ...)`, PostgreSQL 18+). */
  returningOld?: string;
}>;
 
/** Data-modifying statement usable as a CTE body. */
export type ModifyingNode = InsertNode | UpdateNode | DeleteNode;
 
export type StatementNode =
  | SelectNode
  | SetOperationNode
  | InsertNode
  | UpdateNode
  | DeleteNode
  | TruncateNode
  | MergeNode;