All files / src/sql ast.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 7/7
100% Lines 7/7

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                                    463279x         1364x         43776x         7337x         9150x         82x         2840x      
import type {
  BinaryNode,
  ExprNode,
  FnNode,
  IdentNode,
  LogicalNode,
  ParamNode,
  RawNode,
} from './ast-expressions.ts';
 
export type * from './ast-expressions.ts';
export type * from './ast-clauses.ts';
export type * from './ast-statements.ts';
 
/** Factories for the most common AST nodes. Stateless; nodes are plain immutable data. */
export class SqlAst {
  /** Bound parameter (`$n`). */
  param(value: unknown): ParamNode {
    return { kind: 'param', value };
  }
 
  /** Raw SQL text inserted as-is. */
  raw(sql: string): RawNode {
    return { kind: 'raw', sql };
  }
 
  /** Quoted identifier path, e.g. `"table"."column"`. */
  ident(...path: readonly string[]): IdentNode {
    return { kind: 'ident', path };
  }
 
  /** Binary operation `left op right`. */
  binary(op: string, left: ExprNode, right: ExprNode): BinaryNode {
    return { kind: 'binary', op, left, right };
  }
 
  /** Conjunction of the items (`TRUE` when empty). */
  and(items: readonly ExprNode[]): LogicalNode {
    return { kind: 'and', items };
  }
 
  /** Disjunction of the items (`FALSE` when empty). */
  or(items: readonly ExprNode[]): LogicalNode {
    return { kind: 'or', items };
  }
 
  /** Function call `name(args)`. */
  fnCall(name: string, args: readonly ExprNode[]): FnNode {
    return { kind: 'fn', name, args };
  }
}