@prisma-next/sql-relational-core 0.3.0-dev.5 → 0.3.0-dev.50
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.
- package/README.md +18 -2
- package/dist/errors-7_V3El9I.mjs +3 -0
- package/dist/errors-DVufq9PT.d.mts +2 -0
- package/dist/exports/ast.d.mts +192 -0
- package/dist/exports/ast.d.mts.map +1 -0
- package/dist/exports/ast.mjs +361 -0
- package/dist/exports/ast.mjs.map +1 -0
- package/dist/exports/errors.d.mts +2 -0
- package/dist/exports/errors.mjs +3 -0
- package/dist/exports/guards.d.mts +5 -0
- package/dist/exports/guards.mjs +3 -0
- package/dist/exports/operations-registry.d.mts +5 -0
- package/dist/exports/operations-registry.mjs +3 -0
- package/dist/exports/param.d.mts +5 -0
- package/dist/exports/param.mjs +3 -0
- package/dist/exports/plan.d.mts +2 -0
- package/dist/exports/plan.mjs +17 -0
- package/dist/exports/plan.mjs.map +1 -0
- package/dist/exports/query-lane-context.d.mts +2 -0
- package/dist/exports/query-lane-context.mjs +1 -0
- package/dist/exports/schema.d.mts +5 -0
- package/dist/exports/schema.mjs +4 -0
- package/dist/exports/types.d.mts +4 -0
- package/dist/exports/types.mjs +3 -0
- package/dist/exports/utils/guards.d.mts +5 -0
- package/dist/exports/utils/guards.mjs +4 -0
- package/dist/guards-0ycyntYX.mjs +132 -0
- package/dist/guards-0ycyntYX.mjs.map +1 -0
- package/dist/guards-DCCpAlOL.d.mts +87 -0
- package/dist/guards-DCCpAlOL.d.mts.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +12 -0
- package/dist/operations-registry-DPZ5aElH.mjs +152 -0
- package/dist/operations-registry-DPZ5aElH.mjs.map +1 -0
- package/dist/operations-registry-wVEaiLyt.d.mts +9 -0
- package/dist/operations-registry-wVEaiLyt.d.mts.map +1 -0
- package/dist/param-C4n0OW59.d.mts +8 -0
- package/dist/param-C4n0OW59.d.mts.map +1 -0
- package/dist/param-DMU3OWfI.mjs +14 -0
- package/dist/param-DMU3OWfI.mjs.map +1 -0
- package/dist/plan-BhSWuTfw.d.mts +194 -0
- package/dist/plan-BhSWuTfw.d.mts.map +1 -0
- package/dist/query-lane-context-CgkPuKaR.d.mts +259 -0
- package/dist/query-lane-context-CgkPuKaR.d.mts.map +1 -0
- package/dist/schema-Bi5p4aAc.mjs +175 -0
- package/dist/schema-Bi5p4aAc.mjs.map +1 -0
- package/dist/schema-CgrEMqEd.d.mts +86 -0
- package/dist/schema-CgrEMqEd.d.mts.map +1 -0
- package/dist/types-CEUzDuDC.d.mts +447 -0
- package/dist/types-CEUzDuDC.d.mts.map +1 -0
- package/dist/types-Cdi4Whda.mjs +18 -0
- package/dist/types-Cdi4Whda.mjs.map +1 -0
- package/package.json +39 -56
- package/src/ast/codec-types.ts +77 -8
- package/src/ast/delete.ts +2 -2
- package/src/ast/driver-types.ts +20 -3
- package/src/ast/predicate.ts +14 -4
- package/src/ast/select.ts +4 -3
- package/src/ast/sql-codecs.ts +67 -0
- package/src/ast/types.ts +89 -19
- package/src/ast/update.ts +2 -2
- package/src/exports/ast.ts +1 -0
- package/src/exports/guards.ts +5 -0
- package/src/exports/utils/guards.ts +1 -0
- package/src/operations-registry.ts +112 -73
- package/src/query-lane-context.ts +77 -1
- package/src/schema.ts +91 -33
- package/src/types.ts +327 -75
- package/src/utils/guards.ts +88 -18
- package/dist/ast/adapter-types.d.ts +0 -28
- package/dist/ast/adapter-types.d.ts.map +0 -1
- package/dist/ast/codec-types.d.ts +0 -141
- package/dist/ast/codec-types.d.ts.map +0 -1
- package/dist/ast/common.d.ts +0 -7
- package/dist/ast/common.d.ts.map +0 -1
- package/dist/ast/delete.d.ts +0 -8
- package/dist/ast/delete.d.ts.map +0 -1
- package/dist/ast/driver-types.d.ts +0 -20
- package/dist/ast/driver-types.d.ts.map +0 -1
- package/dist/ast/insert.d.ts +0 -8
- package/dist/ast/insert.d.ts.map +0 -1
- package/dist/ast/join.d.ts +0 -6
- package/dist/ast/join.d.ts.map +0 -1
- package/dist/ast/order.d.ts +0 -6
- package/dist/ast/order.d.ts.map +0 -1
- package/dist/ast/predicate.d.ts +0 -4
- package/dist/ast/predicate.d.ts.map +0 -1
- package/dist/ast/select.d.ts +0 -18
- package/dist/ast/select.d.ts.map +0 -1
- package/dist/ast/types.d.ts +0 -118
- package/dist/ast/types.d.ts.map +0 -1
- package/dist/ast/update.d.ts +0 -9
- package/dist/ast/update.d.ts.map +0 -1
- package/dist/ast/util.d.ts +0 -2
- package/dist/ast/util.d.ts.map +0 -1
- package/dist/chunk-2F7DSEOU.js +0 -8
- package/dist/chunk-2F7DSEOU.js.map +0 -1
- package/dist/chunk-36WJWNHT.js +0 -1
- package/dist/chunk-36WJWNHT.js.map +0 -1
- package/dist/chunk-5N34PNVZ.js +0 -62
- package/dist/chunk-5N34PNVZ.js.map +0 -1
- package/dist/chunk-7I3EMQID.js +0 -16
- package/dist/chunk-7I3EMQID.js.map +0 -1
- package/dist/chunk-CBTYMOX2.js +0 -152
- package/dist/chunk-CBTYMOX2.js.map +0 -1
- package/dist/chunk-G52ENULI.js +0 -1
- package/dist/chunk-G52ENULI.js.map +0 -1
- package/dist/chunk-KYSP7L5C.js +0 -16
- package/dist/chunk-KYSP7L5C.js.map +0 -1
- package/dist/chunk-M23L3JHG.js +0 -159
- package/dist/chunk-M23L3JHG.js.map +0 -1
- package/dist/chunk-MM74SVJ4.js +0 -13
- package/dist/chunk-MM74SVJ4.js.map +0 -1
- package/dist/chunk-U7AXAUJA.js +0 -1
- package/dist/chunk-U7AXAUJA.js.map +0 -1
- package/dist/chunk-WZBPVEZI.js +0 -320
- package/dist/chunk-WZBPVEZI.js.map +0 -1
- package/dist/errors.d.ts +0 -2
- package/dist/errors.d.ts.map +0 -1
- package/dist/exports/ast.d.ts +0 -14
- package/dist/exports/ast.d.ts.map +0 -1
- package/dist/exports/ast.js +0 -46
- package/dist/exports/ast.js.map +0 -1
- package/dist/exports/errors.d.ts +0 -2
- package/dist/exports/errors.d.ts.map +0 -1
- package/dist/exports/errors.js +0 -9
- package/dist/exports/errors.js.map +0 -1
- package/dist/exports/guards.d.ts +0 -2
- package/dist/exports/guards.d.ts.map +0 -1
- package/dist/exports/guards.js +0 -21
- package/dist/exports/guards.js.map +0 -1
- package/dist/exports/operations-registry.d.ts +0 -2
- package/dist/exports/operations-registry.d.ts.map +0 -1
- package/dist/exports/operations-registry.js +0 -9
- package/dist/exports/operations-registry.js.map +0 -1
- package/dist/exports/param.d.ts +0 -3
- package/dist/exports/param.d.ts.map +0 -1
- package/dist/exports/param.js +0 -7
- package/dist/exports/param.js.map +0 -1
- package/dist/exports/plan.d.ts +0 -2
- package/dist/exports/plan.d.ts.map +0 -1
- package/dist/exports/plan.js +0 -7
- package/dist/exports/plan.js.map +0 -1
- package/dist/exports/query-lane-context.d.ts +0 -2
- package/dist/exports/query-lane-context.d.ts.map +0 -1
- package/dist/exports/query-lane-context.js +0 -2
- package/dist/exports/query-lane-context.js.map +0 -1
- package/dist/exports/schema.d.ts +0 -3
- package/dist/exports/schema.d.ts.map +0 -1
- package/dist/exports/schema.js +0 -14
- package/dist/exports/schema.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -10
- package/dist/exports/types.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/operations-registry.d.ts +0 -5
- package/dist/operations-registry.d.ts.map +0 -1
- package/dist/param.d.ts +0 -4
- package/dist/param.d.ts.map +0 -1
- package/dist/plan.d.ts +0 -23
- package/dist/plan.d.ts.map +0 -1
- package/dist/query-lane-context.d.ts +0 -16
- package/dist/query-lane-context.d.ts.map +0 -1
- package/dist/schema.d.ts +0 -63
- package/dist/schema.d.ts.map +0 -1
- package/dist/types.d.ts +0 -332
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/guards.d.ts +0 -55
- package/dist/utils/guards.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,9 @@ Provide shared relational primitives (schema builders, column builders, paramete
|
|
|
24
24
|
- **Column Builders**: Provides column accessors with operation methods attached based on column typeId
|
|
25
25
|
- **Parameter Helpers**: Creates parameter placeholders for query building
|
|
26
26
|
- **Operations Registry**: Attaches registered operations as methods on column builders
|
|
27
|
+
- **Execution Context Types**: Defines the context shape used by query lanes
|
|
27
28
|
- **Type Definitions**: Defines TypeScript types for column builders, operations, and projections
|
|
29
|
+
- **Codec Registry Types**: Defines codec interfaces and base SQL codec definitions
|
|
28
30
|
|
|
29
31
|
**Non-goals:**
|
|
30
32
|
- Query DSL construction (sql-lane)
|
|
@@ -42,6 +44,7 @@ flowchart TD
|
|
|
42
44
|
PARAM[Parameter Helpers]
|
|
43
45
|
OPS[Operations Registry]
|
|
44
46
|
TYPES[Type Definitions]
|
|
47
|
+
AST[AST Types]
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
subgraph "Consumers"
|
|
@@ -59,6 +62,8 @@ flowchart TD
|
|
|
59
62
|
OPS --> ORM
|
|
60
63
|
TYPES --> SQL
|
|
61
64
|
TYPES --> ORM
|
|
65
|
+
AST --> SQL
|
|
66
|
+
AST --> ORM
|
|
62
67
|
```
|
|
63
68
|
|
|
64
69
|
## Components
|
|
@@ -86,6 +91,15 @@ flowchart TD
|
|
|
86
91
|
- Defines `SqlQueryPlan<Row>` interface for SQL query plans produced by lanes before lowering
|
|
87
92
|
- Provides `augmentDescriptorWithColumnMeta(descriptors, columnMeta)` helper to update ParamDescriptor with `codecId` and `nativeType` from column metadata
|
|
88
93
|
|
|
94
|
+
### AST Surface (`ast/*` via `exports/ast.ts`)
|
|
95
|
+
- Query roots: `SelectAst`, `InsertAst`, `UpdateAst`, `DeleteAst`
|
|
96
|
+
- Expressions: `ColumnRef`, `ParamRef`, `LiteralExpr`, `OperationExpr`, `ListLiteralExpr`
|
|
97
|
+
- Predicates: `BinaryExpr` (ops: `eq`, `neq`, `gt`, `lt`, `gte`, `lte`, `like`, `ilike`, `in`, `notIn`), `AndExpr`, `OrExpr`, `ExistsExpr`, `NullCheckExpr`
|
|
98
|
+
- Lane-agnostic filter interop: `WhereArg`, `ToWhereExpr`, and `BoundWhereExpr` for passing pre-bound filter payloads without lane-specific types
|
|
99
|
+
- Joins: `JoinAst`, `JoinOnExpr` (eqCol or WhereExpr)
|
|
100
|
+
- `SelectAst.selectAllIntent` — preserves select-all intent when normalized to explicit columns
|
|
101
|
+
- `DeleteAst.where` and `UpdateAst.where` optional for mutation-without-WHERE lint support
|
|
102
|
+
|
|
89
103
|
### Type Definitions (`types.ts`)
|
|
90
104
|
- Defines TypeScript types for column builders, operations, projections
|
|
91
105
|
- Provides type inference utilities for extracting JavaScript types from codec types (e.g., `ExtractJsTypeFromColumnBuilder`)
|
|
@@ -95,9 +109,10 @@ flowchart TD
|
|
|
95
109
|
## Dependencies
|
|
96
110
|
|
|
97
111
|
- **`@prisma-next/contract`**: Core contract types
|
|
112
|
+
- **`@prisma-next/operations`**: Operation registry used by schema builders
|
|
98
113
|
- **`@prisma-next/plan`**: Plan error helpers (`planInvalid`, `planUnsupported`) and `RuntimeError` type
|
|
99
|
-
- **`@prisma-next/
|
|
100
|
-
-
|
|
114
|
+
- **`@prisma-next/sql-contract`**: SQL contract types (via `@prisma-next/sql-contract/types`)
|
|
115
|
+
- **`arktype`**: Parameter schema typing for codec definitions
|
|
101
116
|
|
|
102
117
|
**Note**: This package does not depend on specific adapters (e.g., `@prisma-next/adapter-postgres`). Test fixtures define `CodecTypes` inline to remain adapter-agnostic and avoid cyclic dependencies.
|
|
103
118
|
|
|
@@ -112,6 +127,7 @@ This package follows the standard `exports/` directory pattern:
|
|
|
112
127
|
- `src/exports/types.ts` - Re-exports type definitions
|
|
113
128
|
- `src/exports/operations-registry.ts` - Re-exports operations registry
|
|
114
129
|
- `src/exports/plan.ts` - Re-exports plan types and helpers
|
|
130
|
+
- `src/exports/ast.ts` - Re-exports SQL AST types
|
|
115
131
|
- `src/exports/errors.ts` - Re-exports error helpers (from `@prisma-next/plan`)
|
|
116
132
|
- `src/index.ts` - Main entry point that re-exports from `exports/`
|
|
117
133
|
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { S as defineCodecs, _ as CodecRegistry, b as codec, d as CodecDefBuilder, f as CodecId, g as CodecParamsDescriptor, h as CodecOutput, m as CodecMeta, p as CodecInput, u as Codec, v as ExtractCodecTypes, x as createCodecRegistry, y as ExtractDataTypes } from "../query-lane-context-CgkPuKaR.mjs";
|
|
2
|
+
import { A as WhereArg, C as OrExpr, D as TableRef, E as SelectAst, M as isOperationExpr, O as ToWhereExpr, S as OperationExpr, T as QueryAst, _ as JoinOnExpr, a as BinaryOp, b as LoweredStatement, c as DeleteAst, d as Expression, f as ExpressionSource, g as JoinAst, h as InsertAst, i as BinaryExpr, j as WhereExpr, k as UpdateAst, l as Direction, m as IncludeRef, o as BoundWhereExpr, p as IncludeAst, r as AndExpr, s as ColumnRef, u as ExistsExpr, v as ListLiteralExpr, w as ParamRef, x as NullCheckExpr, y as LiteralExpr } from "../plan-BhSWuTfw.mjs";
|
|
3
|
+
import { b as JoinOnBuilder } from "../types-CEUzDuDC.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/ast/adapter-types.d.ts
|
|
6
|
+
type AdapterTarget = string;
|
|
7
|
+
interface AdapterProfile<TTarget extends AdapterTarget = AdapterTarget> {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly target: TTarget;
|
|
10
|
+
readonly capabilities: Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the adapter's default codec registry.
|
|
13
|
+
* The registry contains codecs provided by the adapter for converting
|
|
14
|
+
* between wire types and JavaScript types.
|
|
15
|
+
*/
|
|
16
|
+
codecs(): CodecRegistry;
|
|
17
|
+
}
|
|
18
|
+
interface LoweredPayload<TBody = unknown> {
|
|
19
|
+
readonly profileId?: string;
|
|
20
|
+
readonly body: TBody;
|
|
21
|
+
readonly annotations?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
interface LowererContext<TContract = unknown> {
|
|
24
|
+
readonly contract: TContract;
|
|
25
|
+
readonly params?: readonly unknown[];
|
|
26
|
+
}
|
|
27
|
+
type Lowerer<Ast = unknown, TContract = unknown, TBody = unknown> = (ast: Ast, context: LowererContext<TContract>) => LoweredPayload<TBody>;
|
|
28
|
+
interface Adapter<Ast = unknown, TContract = unknown, TBody = unknown> {
|
|
29
|
+
readonly profile: AdapterProfile;
|
|
30
|
+
lower(ast: Ast, context: LowererContext<TContract>): LoweredPayload<TBody>;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/ast/common.d.ts
|
|
34
|
+
declare function createTableRef(name: string): TableRef;
|
|
35
|
+
declare function createColumnRef(table: string, column: string): ColumnRef;
|
|
36
|
+
declare function createParamRef(index: number, name?: string): ParamRef;
|
|
37
|
+
declare function createOperationExpr(operation: OperationExpr): OperationExpr;
|
|
38
|
+
declare function createLiteralExpr(value: unknown): LiteralExpr;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/ast/delete.d.ts
|
|
41
|
+
interface CreateDeleteAstOptions {
|
|
42
|
+
readonly table: TableRef;
|
|
43
|
+
readonly where: WhereExpr;
|
|
44
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
45
|
+
}
|
|
46
|
+
declare function createDeleteAst(options: CreateDeleteAstOptions): DeleteAst;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/ast/driver-types.d.ts
|
|
49
|
+
interface SqlExecuteRequest {
|
|
50
|
+
readonly sql: string;
|
|
51
|
+
readonly params?: readonly unknown[];
|
|
52
|
+
}
|
|
53
|
+
interface SqlQueryResult<Row = Record<string, unknown>> {
|
|
54
|
+
readonly rows: ReadonlyArray<Row>;
|
|
55
|
+
readonly rowCount?: number | null;
|
|
56
|
+
readonly [key: string]: unknown;
|
|
57
|
+
}
|
|
58
|
+
interface SqlExplainResult<Row = Record<string, unknown>> {
|
|
59
|
+
readonly rows: ReadonlyArray<Row>;
|
|
60
|
+
}
|
|
61
|
+
type SqlDriverState = 'unbound' | 'connected' | 'closed';
|
|
62
|
+
interface SqlDriver<TBinding = void> extends SqlQueryable {
|
|
63
|
+
readonly state?: SqlDriverState;
|
|
64
|
+
connect(binding: TBinding): Promise<void>;
|
|
65
|
+
acquireConnection(): Promise<SqlConnection>;
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
interface SqlConnection extends SqlQueryable {
|
|
69
|
+
beginTransaction(): Promise<SqlTransaction>;
|
|
70
|
+
release(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
interface SqlTransaction extends SqlQueryable {
|
|
73
|
+
commit(): Promise<void>;
|
|
74
|
+
rollback(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
interface SqlQueryable {
|
|
77
|
+
execute<Row = Record<string, unknown>>(request: SqlExecuteRequest): AsyncIterable<Row>;
|
|
78
|
+
explain?(request: SqlExecuteRequest): Promise<SqlExplainResult>;
|
|
79
|
+
query<Row = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<SqlQueryResult<Row>>;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/ast/insert.d.ts
|
|
83
|
+
interface CreateInsertAstOptions {
|
|
84
|
+
readonly table: TableRef;
|
|
85
|
+
readonly values: Record<string, ColumnRef | ParamRef>;
|
|
86
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
87
|
+
}
|
|
88
|
+
declare function createInsertAst(options: CreateInsertAstOptions): InsertAst;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/ast/join.d.ts
|
|
91
|
+
declare function createJoin(joinType: 'inner' | 'left' | 'right' | 'full', table: TableRef, on: JoinOnExpr): JoinAst;
|
|
92
|
+
declare function createJoinOnExpr(left: ColumnRef, right: ColumnRef): JoinOnExpr;
|
|
93
|
+
declare function createJoinOnBuilder(): JoinOnBuilder;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/ast/order.d.ts
|
|
96
|
+
declare function createOrderByItem(expr: ColumnRef | OperationExpr, dir: 'asc' | 'desc'): {
|
|
97
|
+
expr: ColumnRef | OperationExpr;
|
|
98
|
+
dir: Direction;
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/ast/predicate.d.ts
|
|
102
|
+
declare function createBinaryExpr(op: BinaryOp, left: Expression, right: Expression | ParamRef | LiteralExpr | ListLiteralExpr): BinaryExpr;
|
|
103
|
+
declare function createExistsExpr(not: boolean, subquery: SelectAst): ExistsExpr;
|
|
104
|
+
declare function createNullCheckExpr(expr: Expression, isNull: boolean): NullCheckExpr;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/ast/select.d.ts
|
|
107
|
+
interface CreateSelectAstOptions {
|
|
108
|
+
readonly from: TableRef;
|
|
109
|
+
readonly joins?: ReadonlyArray<JoinAst>;
|
|
110
|
+
readonly includes?: ReadonlyArray<IncludeAst>;
|
|
111
|
+
readonly project: ReadonlyArray<{
|
|
112
|
+
alias: string;
|
|
113
|
+
expr: ColumnRef | IncludeRef | OperationExpr;
|
|
114
|
+
}>;
|
|
115
|
+
readonly where?: WhereExpr;
|
|
116
|
+
readonly orderBy?: ReadonlyArray<{
|
|
117
|
+
expr: ColumnRef | OperationExpr;
|
|
118
|
+
dir: Direction;
|
|
119
|
+
}>;
|
|
120
|
+
readonly limit?: number;
|
|
121
|
+
readonly selectAllIntent?: {
|
|
122
|
+
table?: string;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
declare function createSelectAst(options: CreateSelectAstOptions): SelectAst;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/ast/sql-codecs.d.ts
|
|
128
|
+
declare const SQL_CHAR_CODEC_ID: "sql/char@1";
|
|
129
|
+
declare const SQL_VARCHAR_CODEC_ID: "sql/varchar@1";
|
|
130
|
+
declare const SQL_INT_CODEC_ID: "sql/int@1";
|
|
131
|
+
declare const SQL_FLOAT_CODEC_ID: "sql/float@1";
|
|
132
|
+
declare const codecs: CodecDefBuilder<{
|
|
133
|
+
char: Codec<"sql/char@1", string, string, Record<string, unknown>, unknown>;
|
|
134
|
+
varchar: Codec<"sql/varchar@1", string, string, Record<string, unknown>, unknown>;
|
|
135
|
+
int: Codec<"sql/int@1", number, number, Record<string, unknown>, unknown>;
|
|
136
|
+
} & Record<"float", Codec<"sql/float@1", number, number, Record<string, unknown>, unknown>>>;
|
|
137
|
+
declare const sqlCodecDefinitions: {
|
|
138
|
+
readonly char: {
|
|
139
|
+
readonly typeId: "sql/char@1";
|
|
140
|
+
readonly scalar: "char";
|
|
141
|
+
readonly codec: Codec<"sql/char@1", string, string, Record<string, unknown>, unknown>;
|
|
142
|
+
readonly input: string;
|
|
143
|
+
readonly output: string;
|
|
144
|
+
readonly jsType: string;
|
|
145
|
+
};
|
|
146
|
+
readonly varchar: {
|
|
147
|
+
readonly typeId: "sql/varchar@1";
|
|
148
|
+
readonly scalar: "varchar";
|
|
149
|
+
readonly codec: Codec<"sql/varchar@1", string, string, Record<string, unknown>, unknown>;
|
|
150
|
+
readonly input: string;
|
|
151
|
+
readonly output: string;
|
|
152
|
+
readonly jsType: string;
|
|
153
|
+
};
|
|
154
|
+
readonly int: {
|
|
155
|
+
readonly typeId: "sql/int@1";
|
|
156
|
+
readonly scalar: "int";
|
|
157
|
+
readonly codec: Codec<"sql/int@1", number, number, Record<string, unknown>, unknown>;
|
|
158
|
+
readonly input: number;
|
|
159
|
+
readonly output: number;
|
|
160
|
+
readonly jsType: number;
|
|
161
|
+
};
|
|
162
|
+
readonly float: {
|
|
163
|
+
readonly typeId: "sql/float@1";
|
|
164
|
+
readonly scalar: "float";
|
|
165
|
+
readonly codec: Codec<"sql/float@1", number, number, Record<string, unknown>, unknown>;
|
|
166
|
+
readonly input: number;
|
|
167
|
+
readonly output: number;
|
|
168
|
+
readonly jsType: number;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
declare const sqlDataTypes: {
|
|
172
|
+
readonly char: "sql/char@1";
|
|
173
|
+
readonly varchar: "sql/varchar@1";
|
|
174
|
+
readonly int: "sql/int@1";
|
|
175
|
+
readonly float: "sql/float@1";
|
|
176
|
+
};
|
|
177
|
+
type SqlCodecTypes = typeof codecs.CodecTypes;
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/ast/update.d.ts
|
|
180
|
+
interface CreateUpdateAstOptions {
|
|
181
|
+
readonly table: TableRef;
|
|
182
|
+
readonly set: Record<string, ColumnRef | ParamRef>;
|
|
183
|
+
readonly where?: WhereExpr;
|
|
184
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
185
|
+
}
|
|
186
|
+
declare function createUpdateAst(options: CreateUpdateAstOptions): UpdateAst;
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/ast/util.d.ts
|
|
189
|
+
declare function compact<T extends Record<string, unknown>>(o: T): T;
|
|
190
|
+
//#endregion
|
|
191
|
+
export { Adapter, AdapterProfile, AdapterTarget, AndExpr, BinaryExpr, BinaryOp, BoundWhereExpr, Codec, CodecDefBuilder, CodecId, CodecInput, CodecMeta, CodecOutput, CodecParamsDescriptor, CodecRegistry, ColumnRef, CreateDeleteAstOptions, CreateInsertAstOptions, CreateSelectAstOptions, CreateUpdateAstOptions, DeleteAst, Direction, ExistsExpr, Expression, ExpressionSource, ExtractCodecTypes, ExtractDataTypes, IncludeAst, IncludeRef, InsertAst, JoinAst, JoinOnExpr, ListLiteralExpr, LiteralExpr, LoweredPayload, LoweredStatement, Lowerer, LowererContext, NullCheckExpr, OperationExpr, OrExpr, ParamRef, QueryAst, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_VARCHAR_CODEC_ID, SelectAst, SqlCodecTypes, SqlConnection, SqlDriver, SqlDriverState, SqlExecuteRequest, SqlExplainResult, SqlQueryResult, SqlQueryable, SqlTransaction, TableRef, ToWhereExpr, UpdateAst, WhereArg, WhereExpr, codec, compact, createBinaryExpr, createCodecRegistry, createColumnRef, createDeleteAst, createExistsExpr, createInsertAst, createJoin, createJoinOnBuilder, createJoinOnExpr, createLiteralExpr, createNullCheckExpr, createOperationExpr, createOrderByItem, createParamRef, createSelectAst, createTableRef, createUpdateAst, defineCodecs, isOperationExpr, sqlCodecDefinitions, sqlDataTypes };
|
|
192
|
+
//# sourceMappingURL=ast.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.mts","names":[],"sources":["../../src/ast/adapter-types.ts","../../src/ast/common.ts","../../src/ast/delete.ts","../../src/ast/driver-types.ts","../../src/ast/insert.ts","../../src/ast/join.ts","../../src/ast/order.ts","../../src/ast/predicate.ts","../../src/ast/select.ts","../../src/ast/sql-codecs.ts","../../src/ast/update.ts","../../src/ast/util.ts"],"sourcesContent":[],"mappings":";;;;;KAEY,aAAA;UAEK,+BAA+B,gBAAgB;;mBAE7C;EAJP,SAAA,YAAa,EAKA,MALA,CAAA,MAAA,EAAA,OAAA,CAAA;EAER;;;;;EASL,MAAA,EAAA,EAAA,aAAA;;AAGK,UAAA,cAAc,CAAA,QAEd,OACQ,CAAA,CAAA;EAGR,SAAA,SAAc,CAAA,EAAA,MAAA;EAKnB,SAAA,IAAO,EATF,KASE;EACZ,SAAA,WAAA,CAAA,EATkB,MASlB,CAAA,MAAA,EAAA,OAAA,CAAA;;AACI,UAPM,cAON,CAAA,YAAA,OAAA,CAAA,CAAA;EACS,SAAA,QAAA,EAPC,SAOD;EAAf,SAAA,MAAA,CAAA,EAAA,SAAA,OAAA,EAAA;;AAEY,KALL,OAKY,CAAA,MAAA,OAAA,EAAA,YAAA,OAAA,EAAA,QAAA,OAAA,CAAA,GAAA,CAAA,GAAA,EAJjB,GAIiB,EAAA,OAAA,EAHb,cAGa,CAHE,SAGF,CAAA,EAAA,GAFnB,cAEmB,CAFJ,KAEI,CAAA;AACJ,UADH,OACG,CAAA,MAAA,OAAA,EA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MAAA;EAA6B,CAAA;EAAf,SAAA,GAAA,EAAA;IAA2C,SAAA,MAAA,EAAA,WAAA;IAAf,SAAA,MAAA,EAAA,KAAA;IAAc,SAAA,KAAA,OAAA,CAAA,WAAA,EAAA,MAAA,EAAA,MAAA,QAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,CAAA;;;;EC/BrD,CAAA;EAOA,SAAA,KAAA,EAAA;IAQA,SAAA,MAAc,EAAA,aAAgC;IAQ9C,SAAA,MAAA,EAAA,OAAmB;IAInB,SAAA,KAAA,OAA8C,CAAA,aAAA,EAAA,MAAA,EAAA,MAAA,QAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,CAAA;;;;EC3B7C,CAAA;CACC;AACA,cO4DL,YP5DK,EAAA;EACmB,SAAA,IAAA,EAAA,YAAA;EAAd,SAAA,OAAA,EAAA,eAAA;EAAa,SAAA,GAAA,EAAA,WAAA;EAGpB,SAAA,KAAA,EAAA,aAAe;;KOyDnB,aAAA,UAAuB,MAAA,CAAO;;;UC/DzB,sBAAA;kBACC;gBACF,eAAe,YAAY;mBACxB;EVJP,SAAA,SAAa,CAAA,EUKF,aVLE,CUKY,SVLZ,CAAA;AAEzB;AAAgD,iBUMhC,eAAA,CVNgC,OAAA,EUMP,sBVNO,CAAA,EUMkB,SVNlB;;;iBWJhC,kBAAkB,4BAA4B,IAAI"}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { n as isColumnBuilder } from "../types-Cdi4Whda.mjs";
|
|
2
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
3
|
+
import { planInvalid } from "@prisma-next/plan";
|
|
4
|
+
import { type } from "arktype";
|
|
5
|
+
|
|
6
|
+
//#region src/ast/codec-types.ts
|
|
7
|
+
/**
|
|
8
|
+
* Implementation of CodecRegistry.
|
|
9
|
+
*/
|
|
10
|
+
var CodecRegistryImpl = class {
|
|
11
|
+
_byId = /* @__PURE__ */ new Map();
|
|
12
|
+
_byScalar = /* @__PURE__ */ new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Map-like interface for codec lookup by ID.
|
|
15
|
+
* Example: registry.get('pg/text@1')
|
|
16
|
+
*/
|
|
17
|
+
get(id) {
|
|
18
|
+
return this._byId.get(id);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if a codec with the given ID is registered.
|
|
22
|
+
*/
|
|
23
|
+
has(id) {
|
|
24
|
+
return this._byId.has(id);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get all codecs that handle a given scalar type.
|
|
28
|
+
* Returns an empty frozen array if no codecs are found.
|
|
29
|
+
* Example: registry.getByScalar('text') → [codec1, codec2, ...]
|
|
30
|
+
*/
|
|
31
|
+
getByScalar(scalar) {
|
|
32
|
+
return this._byScalar.get(scalar) ?? Object.freeze([]);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the default codec for a scalar type (first registered codec).
|
|
36
|
+
* Returns undefined if no codec handles this scalar type.
|
|
37
|
+
*/
|
|
38
|
+
getDefaultCodec(scalar) {
|
|
39
|
+
return this._byScalar.get(scalar)?.[0];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register a codec in the registry.
|
|
43
|
+
* Throws an error if a codec with the same ID is already registered.
|
|
44
|
+
*
|
|
45
|
+
* @param codec - The codec to register
|
|
46
|
+
* @throws Error if a codec with the same ID already exists
|
|
47
|
+
*/
|
|
48
|
+
register(codec$1) {
|
|
49
|
+
if (this._byId.has(codec$1.id)) throw new Error(`Codec with ID '${codec$1.id}' is already registered`);
|
|
50
|
+
this._byId.set(codec$1.id, codec$1);
|
|
51
|
+
for (const scalarType of codec$1.targetTypes) {
|
|
52
|
+
const existing = this._byScalar.get(scalarType);
|
|
53
|
+
if (existing) existing.push(codec$1);
|
|
54
|
+
else this._byScalar.set(scalarType, [codec$1]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns an iterator over all registered codecs.
|
|
59
|
+
* Useful for iterating through codecs from another registry.
|
|
60
|
+
*/
|
|
61
|
+
*[Symbol.iterator]() {
|
|
62
|
+
for (const codec$1 of this._byId.values()) yield codec$1;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns an iterable of all registered codecs.
|
|
66
|
+
*/
|
|
67
|
+
values() {
|
|
68
|
+
return this._byId.values();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Codec factory - creates a codec with typeId and encode/decode functions.
|
|
73
|
+
*/
|
|
74
|
+
function codec(config) {
|
|
75
|
+
return {
|
|
76
|
+
id: config.typeId,
|
|
77
|
+
targetTypes: config.targetTypes,
|
|
78
|
+
...ifDefined("meta", config.meta),
|
|
79
|
+
...ifDefined("paramsSchema", config.paramsSchema),
|
|
80
|
+
...ifDefined("init", config.init),
|
|
81
|
+
encode: config.encode,
|
|
82
|
+
decode: config.decode
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Implementation of CodecDefBuilder.
|
|
87
|
+
*/
|
|
88
|
+
var CodecDefBuilderImpl = class CodecDefBuilderImpl {
|
|
89
|
+
_codecs;
|
|
90
|
+
CodecTypes;
|
|
91
|
+
dataTypes;
|
|
92
|
+
constructor(codecs$1) {
|
|
93
|
+
this._codecs = codecs$1;
|
|
94
|
+
const codecTypes = {};
|
|
95
|
+
for (const [, codecImpl] of Object.entries(this._codecs)) {
|
|
96
|
+
const codecImplTyped = codecImpl;
|
|
97
|
+
codecTypes[codecImplTyped.id] = {
|
|
98
|
+
input: void 0,
|
|
99
|
+
output: void 0
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
this.CodecTypes = codecTypes;
|
|
103
|
+
const dataTypes = {};
|
|
104
|
+
for (const key in this._codecs) if (Object.hasOwn(this._codecs, key)) dataTypes[key] = this._codecs[key].id;
|
|
105
|
+
this.dataTypes = dataTypes;
|
|
106
|
+
}
|
|
107
|
+
add(scalarName, codecImpl) {
|
|
108
|
+
return new CodecDefBuilderImpl({
|
|
109
|
+
...this._codecs,
|
|
110
|
+
[scalarName]: codecImpl
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Derive codecDefinitions structure.
|
|
115
|
+
*/
|
|
116
|
+
get codecDefinitions() {
|
|
117
|
+
const result = {};
|
|
118
|
+
for (const [scalarName, codecImpl] of Object.entries(this._codecs)) {
|
|
119
|
+
const codec$1 = codecImpl;
|
|
120
|
+
result[scalarName] = {
|
|
121
|
+
typeId: codec$1.id,
|
|
122
|
+
scalar: scalarName,
|
|
123
|
+
codec: codec$1,
|
|
124
|
+
input: void 0,
|
|
125
|
+
output: void 0,
|
|
126
|
+
jsType: void 0
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Create a new codec registry.
|
|
134
|
+
*/
|
|
135
|
+
function createCodecRegistry() {
|
|
136
|
+
return new CodecRegistryImpl();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create a new codec definition builder.
|
|
140
|
+
*/
|
|
141
|
+
function defineCodecs() {
|
|
142
|
+
return new CodecDefBuilderImpl({});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/ast/util.ts
|
|
147
|
+
function compact(o) {
|
|
148
|
+
const out = {};
|
|
149
|
+
for (const [k, v] of Object.entries(o)) {
|
|
150
|
+
if (v === void 0 || v === null) continue;
|
|
151
|
+
if (Array.isArray(v) && v.length === 0) continue;
|
|
152
|
+
out[k] = v;
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/ast/common.ts
|
|
159
|
+
function createTableRef(name) {
|
|
160
|
+
return {
|
|
161
|
+
kind: "table",
|
|
162
|
+
name
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function createColumnRef(table, column) {
|
|
166
|
+
return {
|
|
167
|
+
kind: "col",
|
|
168
|
+
table,
|
|
169
|
+
column
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function createParamRef(index, name) {
|
|
173
|
+
return compact({
|
|
174
|
+
kind: "param",
|
|
175
|
+
index,
|
|
176
|
+
name
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function createOperationExpr(operation) {
|
|
180
|
+
return operation;
|
|
181
|
+
}
|
|
182
|
+
function createLiteralExpr(value) {
|
|
183
|
+
return {
|
|
184
|
+
kind: "literal",
|
|
185
|
+
value
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/ast/delete.ts
|
|
191
|
+
function createDeleteAst(options) {
|
|
192
|
+
return compact({
|
|
193
|
+
kind: "delete",
|
|
194
|
+
table: options.table,
|
|
195
|
+
where: options.where,
|
|
196
|
+
returning: options.returning
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/ast/insert.ts
|
|
202
|
+
function createInsertAst(options) {
|
|
203
|
+
return compact({
|
|
204
|
+
kind: "insert",
|
|
205
|
+
table: options.table,
|
|
206
|
+
values: options.values,
|
|
207
|
+
returning: options.returning
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/ast/join.ts
|
|
213
|
+
function createJoin(joinType, table, on) {
|
|
214
|
+
return {
|
|
215
|
+
kind: "join",
|
|
216
|
+
joinType,
|
|
217
|
+
table,
|
|
218
|
+
on
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function createJoinOnExpr(left, right) {
|
|
222
|
+
return {
|
|
223
|
+
kind: "eqCol",
|
|
224
|
+
left,
|
|
225
|
+
right
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
var JoinOnBuilderImpl = class {
|
|
229
|
+
eqCol(left, right) {
|
|
230
|
+
if (!left || !isColumnBuilder(left)) throw planInvalid("Join ON left operand must be a column");
|
|
231
|
+
if (!right || !isColumnBuilder(right)) throw planInvalid("Join ON right operand must be a column");
|
|
232
|
+
const leftCol = left;
|
|
233
|
+
const rightCol = right;
|
|
234
|
+
if (leftCol.table === rightCol.table) throw planInvalid("Self-joins are not supported in MVP");
|
|
235
|
+
return {
|
|
236
|
+
kind: "join-on",
|
|
237
|
+
left,
|
|
238
|
+
right
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
function createJoinOnBuilder() {
|
|
243
|
+
return new JoinOnBuilderImpl();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/ast/order.ts
|
|
248
|
+
function createOrderByItem(expr, dir) {
|
|
249
|
+
return {
|
|
250
|
+
expr,
|
|
251
|
+
dir
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/ast/predicate.ts
|
|
257
|
+
function createBinaryExpr(op, left, right) {
|
|
258
|
+
return {
|
|
259
|
+
kind: "bin",
|
|
260
|
+
op,
|
|
261
|
+
left,
|
|
262
|
+
right
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function createExistsExpr(not, subquery) {
|
|
266
|
+
return {
|
|
267
|
+
kind: "exists",
|
|
268
|
+
not,
|
|
269
|
+
subquery
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function createNullCheckExpr(expr, isNull) {
|
|
273
|
+
return {
|
|
274
|
+
kind: "nullCheck",
|
|
275
|
+
expr,
|
|
276
|
+
isNull
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/ast/select.ts
|
|
282
|
+
function createSelectAst(options) {
|
|
283
|
+
return compact({
|
|
284
|
+
kind: "select",
|
|
285
|
+
from: options.from,
|
|
286
|
+
joins: options.joins,
|
|
287
|
+
includes: options.includes,
|
|
288
|
+
project: options.project,
|
|
289
|
+
where: options.where,
|
|
290
|
+
orderBy: options.orderBy,
|
|
291
|
+
limit: options.limit,
|
|
292
|
+
selectAllIntent: options.selectAllIntent
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/ast/sql-codecs.ts
|
|
298
|
+
const SQL_CHAR_CODEC_ID = "sql/char@1";
|
|
299
|
+
const SQL_VARCHAR_CODEC_ID = "sql/varchar@1";
|
|
300
|
+
const SQL_INT_CODEC_ID = "sql/int@1";
|
|
301
|
+
const SQL_FLOAT_CODEC_ID = "sql/float@1";
|
|
302
|
+
const lengthParamsSchema = type({ length: "number.integer > 0" });
|
|
303
|
+
function createLengthTypeHelper(kind) {
|
|
304
|
+
return (params) => ({
|
|
305
|
+
kind,
|
|
306
|
+
maxLength: params["length"]
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
const sqlCharCodec = codec({
|
|
310
|
+
typeId: SQL_CHAR_CODEC_ID,
|
|
311
|
+
targetTypes: ["char"],
|
|
312
|
+
encode: (value) => value,
|
|
313
|
+
decode: (wire) => wire.trimEnd(),
|
|
314
|
+
paramsSchema: lengthParamsSchema,
|
|
315
|
+
init: createLengthTypeHelper("fixed")
|
|
316
|
+
});
|
|
317
|
+
const sqlVarcharCodec = codec({
|
|
318
|
+
typeId: SQL_VARCHAR_CODEC_ID,
|
|
319
|
+
targetTypes: ["varchar"],
|
|
320
|
+
encode: (value) => value,
|
|
321
|
+
decode: (wire) => wire,
|
|
322
|
+
paramsSchema: lengthParamsSchema,
|
|
323
|
+
init: createLengthTypeHelper("variable")
|
|
324
|
+
});
|
|
325
|
+
const sqlIntCodec = codec({
|
|
326
|
+
typeId: SQL_INT_CODEC_ID,
|
|
327
|
+
targetTypes: ["int"],
|
|
328
|
+
encode: (value) => value,
|
|
329
|
+
decode: (wire) => wire
|
|
330
|
+
});
|
|
331
|
+
const sqlFloatCodec = codec({
|
|
332
|
+
typeId: SQL_FLOAT_CODEC_ID,
|
|
333
|
+
targetTypes: ["float"],
|
|
334
|
+
encode: (value) => value,
|
|
335
|
+
decode: (wire) => wire
|
|
336
|
+
});
|
|
337
|
+
const codecs = defineCodecs().add("char", sqlCharCodec).add("varchar", sqlVarcharCodec).add("int", sqlIntCodec).add("float", sqlFloatCodec);
|
|
338
|
+
const sqlCodecDefinitions = codecs.codecDefinitions;
|
|
339
|
+
const sqlDataTypes = codecs.dataTypes;
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/ast/types.ts
|
|
343
|
+
function isOperationExpr(expr) {
|
|
344
|
+
return expr.kind === "operation";
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/ast/update.ts
|
|
349
|
+
function createUpdateAst(options) {
|
|
350
|
+
return compact({
|
|
351
|
+
kind: "update",
|
|
352
|
+
table: options.table,
|
|
353
|
+
set: options.set,
|
|
354
|
+
where: options.where,
|
|
355
|
+
returning: options.returning
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
//#endregion
|
|
360
|
+
export { SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_VARCHAR_CODEC_ID, codec, compact, createBinaryExpr, createCodecRegistry, createColumnRef, createDeleteAst, createExistsExpr, createInsertAst, createJoin, createJoinOnBuilder, createJoinOnExpr, createLiteralExpr, createNullCheckExpr, createOperationExpr, createOrderByItem, createParamRef, createSelectAst, createTableRef, createUpdateAst, defineCodecs, isOperationExpr, sqlCodecDefinitions, sqlDataTypes };
|
|
361
|
+
//# sourceMappingURL=ast.mjs.map
|