@crvouga/postgres-mem 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ import type { Expr, SelectStmt, TypeName } from "../ast/nodes.js";
2
+ import type { FunctionData } from "../storage/database-state.js";
3
+ import type { TypedValue } from "../types/value.js";
4
+ import { type ExecEnv, type Relation } from "./relation.js";
5
+ /**
6
+ * plpgsql-lite: DECLARE, nested BEGIN/EXCEPTION WHEN others, IF, CASE,
7
+ * assignment, RETURN / RETURN NEXT, PERFORM, FOR-IN-SELECT.
8
+ */
9
+ export type PlStmt = {
10
+ kind: "assign";
11
+ target: string[];
12
+ expr: Expr;
13
+ } | {
14
+ kind: "return_new";
15
+ } | {
16
+ kind: "return_old";
17
+ } | {
18
+ kind: "return_expr";
19
+ expr: Expr;
20
+ } | {
21
+ kind: "return_empty";
22
+ } | {
23
+ kind: "return_next";
24
+ } | {
25
+ kind: "if";
26
+ branches: Array<{
27
+ cond: Expr;
28
+ body: PlStmt[];
29
+ }>;
30
+ elseBody: PlStmt[];
31
+ } | {
32
+ kind: "case";
33
+ expr: Expr | null;
34
+ branches: Array<{
35
+ cond: Expr;
36
+ body: PlStmt[];
37
+ }>;
38
+ elseBody: PlStmt[];
39
+ } | {
40
+ kind: "null";
41
+ } | {
42
+ kind: "raise";
43
+ message: string;
44
+ } | {
45
+ kind: "perform";
46
+ expr: Expr;
47
+ } | {
48
+ kind: "block";
49
+ body: PlStmt[];
50
+ handler: PlStmt[] | null;
51
+ } | {
52
+ kind: "for";
53
+ targets: string[];
54
+ query: SelectStmt;
55
+ body: PlStmt[];
56
+ };
57
+ export interface PlDecl {
58
+ name: string;
59
+ typeName: TypeName;
60
+ init: Expr | null;
61
+ }
62
+ export interface PlProgram {
63
+ decls: PlDecl[];
64
+ body: PlStmt[];
65
+ }
66
+ export declare function compilePlpgsql(raw: string): PlProgram;
67
+ export declare function compileTriggerBody(raw: string): PlStmt[];
68
+ export declare function callPlpgsqlScalar(env: ExecEnv, fn: FunctionData, args: TypedValue[]): TypedValue;
69
+ export declare function callPlpgsqlSet(env: ExecEnv, fn: FunctionData, args: TypedValue[]): Relation;
@@ -20,6 +20,8 @@ export declare function evalScalar(env: ExecEnv, scope: RowScope | null, e: Expr
20
20
  /** SQL three-valued predicate: null → false */
21
21
  export declare function evalPredicate(env: ExecEnv, scope: RowScope | null, e: Expr, extras?: ScopeExtras): boolean;
22
22
  export declare function resolveUserFunction(env: ExecEnv, name: string[], argCount: number): FunctionData | null;
23
+ /** Prefer a UDF whose declared types accept the actual args via implicit cast. */
24
+ export declare function resolveUserFunctionForArgs(env: ExecEnv, name: string[], args: TypedValue[]): FunctionData | null;
23
25
  export declare function callSqlFunctionScalar(env: ExecEnv, fn: FunctionData, args: TypedValue[]): TypedValue;
24
26
  export declare function callSqlFunctionSet(env: ExecEnv, fn: FunctionData, args: TypedValue[]): Relation;
25
27
  export declare function applyWith(env: ExecEnv, w: WithClause | null): ExecEnv;
@@ -27,7 +29,7 @@ interface Source {
27
29
  rel: Relation;
28
30
  rangeVars: Set<string>;
29
31
  }
30
- export declare function buildFrom(env: ExecEnv, items: FromItem[]): Source;
32
+ export declare function buildFrom(env: ExecEnv, items: FromItem[], where?: Expr | null): Source;
31
33
  export interface SortSpec {
32
34
  colIdx: number;
33
35
  dir: "asc" | "desc";
package/dist/index.d.ts CHANGED
@@ -23,6 +23,6 @@
23
23
  */
24
24
  import "./serialization/codec.js";
25
25
  export type { BindValue, JsValue, QueryRow } from "./api/bind.js";
26
- export { Database, type DatabaseOptions } from "./api/database.js";
26
+ export { Database, type DatabaseOptions, type RegisterFunctionOptions, Snapshot } from "./api/database.js";
27
27
  export { type ResultSet, type RunResult, Statement } from "./api/statement.js";
28
28
  export { type ErrorCategory, PostgresError } from "./errors/error.js";