@vibeorm/sql 2.0.0-alpha.1
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 +58 -0
- package/dist/ast.d.ts +474 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/capabilities.d.ts +13 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/codecs.d.ts +95 -0
- package/dist/codecs.d.ts.map +1 -0
- package/dist/dialect.d.ts +103 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dialects/mysql.d.ts +15 -0
- package/dist/dialects/mysql.d.ts.map +1 -0
- package/dist/dialects/postgres.d.ts +7 -0
- package/dist/dialects/postgres.d.ts.map +1 -0
- package/dist/dialects/registry.d.ts +14 -0
- package/dist/dialects/registry.d.ts.map +1 -0
- package/dist/dialects/sqlite.d.ts +12 -0
- package/dist/dialects/sqlite.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1030 -0
- package/dist/index.js.map +19 -0
- package/dist/like.d.ts +44 -0
- package/dist/like.d.ts.map +1 -0
- package/dist/params.d.ts +17 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/render.d.ts +46 -0
- package/dist/render.d.ts.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SqlDialect contract: every decision about SQL text, per dialect.
|
|
3
|
+
*
|
|
4
|
+
* Renderers (render.ts) contain the shared statement grammar and switch on the
|
|
5
|
+
* explicit strategy fields declared here — so each divergence between dialects
|
|
6
|
+
* is named, visible and individually testable.
|
|
7
|
+
*/
|
|
8
|
+
import type { Dialect, DialectCapabilities } from "@vibeorm/schema";
|
|
9
|
+
import type { JsonFilterOp } from "./ast.ts";
|
|
10
|
+
export type SqlDialect = {
|
|
11
|
+
readonly name: Dialect;
|
|
12
|
+
/** Frozen feature table — consumed by runtime, migrate, generator, tests. */
|
|
13
|
+
readonly capabilities: DialectCapabilities;
|
|
14
|
+
/** Array membership: `col = ANY($n)` with one array param, or `IN (?, ?, …)` expansion. */
|
|
15
|
+
readonly inArrayStrategy: "any" | "expand";
|
|
16
|
+
/** Upsert clause form. */
|
|
17
|
+
readonly upsertForm: "onConflict" | "onDuplicateKey";
|
|
18
|
+
/**
|
|
19
|
+
* Skip-conflicting-rows form. `onConflictDoNothing` appends
|
|
20
|
+
* `ON CONFLICT [(target)] DO NOTHING`; `insertIgnore` turns the statement into
|
|
21
|
+
* `INSERT IGNORE INTO` — which ignores a wider class of errors than a pure
|
|
22
|
+
* duplicate-key skip (see the catalog case).
|
|
23
|
+
*/
|
|
24
|
+
readonly doNothingForm: "onConflictDoNothing" | "insertIgnore";
|
|
25
|
+
/** Case-insensitive LIKE: native ILIKE or LOWER(col) LIKE LOWER(pattern). */
|
|
26
|
+
readonly insensitiveLike: "ilike" | "lower";
|
|
27
|
+
/**
|
|
28
|
+
* Case-SENSITIVE string matching (`mode: "strict"`, board #20): `native`
|
|
29
|
+
* where the default `=`/`LIKE` are already byte-sensitive (postgres),
|
|
30
|
+
* `glob` for sqlite's byte-exact GLOB (its LIKE is ASCII-case-insensitive),
|
|
31
|
+
* `binary` for mysql's CAST-to-BINARY operand (its `_ci` collations fold
|
|
32
|
+
* `=`, `IN` and `LIKE`). The pattern forms defeat plain indexes on the
|
|
33
|
+
* non-native dialects — documented in docs/dialect-notes.md.
|
|
34
|
+
*/
|
|
35
|
+
readonly strictMatchStrategy: "native" | "glob" | "binary";
|
|
36
|
+
/** ORDER BY NULLS FIRST/LAST: native clause or `col IS NULL` emulation term. */
|
|
37
|
+
readonly orderByNullsMode: "native" | "emulate";
|
|
38
|
+
/** Dialects where OFFSET requires a LIMIT clause declare the filler literal. */
|
|
39
|
+
readonly offsetRequiresLimit: {
|
|
40
|
+
readonly limitText: string;
|
|
41
|
+
} | null;
|
|
42
|
+
/** Appended verbatim after LIKE patterns (sqlite needs an explicit ESCAPE clause). */
|
|
43
|
+
readonly likeEscapeClause: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* How JSON path predicates render: postgres `#>`/`#>>` operators with a
|
|
46
|
+
* bound `text[]` path, sqlite `json_extract(col, ?)`, mysql
|
|
47
|
+
* `JSON_EXTRACT`/`JSON_UNQUOTE`/`JSON_CONTAINS` — all with a bound
|
|
48
|
+
* `$.a.b[0]` path string.
|
|
49
|
+
*/
|
|
50
|
+
readonly jsonPathMode: "operators" | "sqliteExtract" | "mysqlExtract";
|
|
51
|
+
/**
|
|
52
|
+
* JSON filter ops this dialect can express. The runtime gates at build time
|
|
53
|
+
* and the renderer refuses too (dialect honesty) — both read this list, so
|
|
54
|
+
* claim and behaviour cannot drift.
|
|
55
|
+
*/
|
|
56
|
+
readonly supportedJsonOps: readonly JsonFilterOp[];
|
|
57
|
+
/**
|
|
58
|
+
* Cast suffix pinning a Json PARAMETER's type at write and compare sites
|
|
59
|
+
* (`$n::text::jsonb` on postgres). OID-typed drivers (bun:sql) re-serialize
|
|
60
|
+
* the JS value as the parameter's resolved type — a pre-stringified Json
|
|
61
|
+
* param in a bare jsonb slot arrives double-encoded — so the text cast makes
|
|
62
|
+
* the SERVER parse the document, identically for every driver. Empty where
|
|
63
|
+
* Json transport is already plain text (sqlite/mysql). Rendered for
|
|
64
|
+
* {@link JsonParamCell} cells and the json-filter operands.
|
|
65
|
+
*/
|
|
66
|
+
readonly jsonParamCast: string;
|
|
67
|
+
/**
|
|
68
|
+
* Statement that reads back the id generated by the previous INSERT, for
|
|
69
|
+
* dialects without RETURNING. `null` where RETURNING covers it. The single
|
|
70
|
+
* result column is always named `id`.
|
|
71
|
+
*/
|
|
72
|
+
readonly lastInsertIdSql: string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Row-lock clause appended for `SelectStatement.lockForUpdate` (" FOR
|
|
75
|
+
* UPDATE"), or `null` where the dialect has none. Sqlite is `null` and
|
|
76
|
+
* honestly so: it has no row locks, and its single-writer transactions make
|
|
77
|
+
* the read-modify-write overlays race-free without one.
|
|
78
|
+
*/
|
|
79
|
+
readonly selectForUpdate: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* Whether a multi-row INSERT may write the per-row `DEFAULT` keyword in a
|
|
82
|
+
* VALUES cell (postgres/mysql). Sqlite cannot — heterogeneous createMany
|
|
83
|
+
* rows are grouped by column set into separate statements there (M4).
|
|
84
|
+
*/
|
|
85
|
+
readonly rowDefaultKeyword: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Conservative bound-parameter budget per statement (M7). Hard limits:
|
|
88
|
+
* sqlite errors past SQLITE_MAX_VARIABLE_NUMBER (32766 by default), mysql
|
|
89
|
+
* caps placeholders at 65535, postgres's extended protocol at 65535. The
|
|
90
|
+
* runtime chunks unbounded parameter producers — relation WHERE…IN batches
|
|
91
|
+
* on expand dialects, createMany rows — to stay far under them.
|
|
92
|
+
*/
|
|
93
|
+
readonly paramBudget: number;
|
|
94
|
+
/** Quote an identifier, escaping embedded quote characters. */
|
|
95
|
+
quoteIdent(params: {
|
|
96
|
+
name: string;
|
|
97
|
+
}): string;
|
|
98
|
+
/** Positional placeholder for the 1-based parameter index ($n or ?). */
|
|
99
|
+
placeholder(params: {
|
|
100
|
+
index: number;
|
|
101
|
+
}): string;
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAG3C,2FAA2F;IAC3F,QAAQ,CAAC,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EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC;CAChD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL dialect (mysql2 adapter lands in P4).
|
|
3
|
+
*
|
|
4
|
+
* Notes pinned by catalog cases:
|
|
5
|
+
* - No RETURNING → renderer omits it and flags `returning: "omitted"`; the
|
|
6
|
+
* runtime re-selects by PK (app-generated ids) or insertId.
|
|
7
|
+
* - Upserts use ON DUPLICATE KEY UPDATE (no conflict-target refinement).
|
|
8
|
+
* - OFFSET requires LIMIT → the documented huge-limit idiom.
|
|
9
|
+
* - No NULLS FIRST/LAST → `col IS NULL` emulation terms.
|
|
10
|
+
* - No `ON CONFLICT ... DO NOTHING` → `INSERT IGNORE`, which is broader: it
|
|
11
|
+
* downgrades other row-level errors to warnings too.
|
|
12
|
+
*/
|
|
13
|
+
import type { SqlDialect } from "../dialect.ts";
|
|
14
|
+
export declare const mysqlDialect: SqlDialect;
|
|
15
|
+
//# sourceMappingURL=mysql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/dialects/mysql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,eAAO,MAAM,YAAY,EAAE,UAyC1B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL dialect. Also serves PGlite — the differences are adapter-level
|
|
3
|
+
* (single connection, bundled extension set), not SQL-text-level.
|
|
4
|
+
*/
|
|
5
|
+
import type { SqlDialect } from "../dialect.ts";
|
|
6
|
+
export declare const postgresDialect: SqlDialect;
|
|
7
|
+
//# sourceMappingURL=postgres.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/dialects/postgres.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,eAAO,MAAM,eAAe,EAAE,UAsC7B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dialect registry: the one place a `Dialect` name becomes a `SqlDialect`.
|
|
3
|
+
*
|
|
4
|
+
* Runtime and adapters resolve through this map so nobody re-implements the
|
|
5
|
+
* lookup (and nobody can quietly forget a dialect — the Record type is total).
|
|
6
|
+
*/
|
|
7
|
+
import type { Dialect } from "@vibeorm/schema";
|
|
8
|
+
import type { SqlDialect } from "../dialect.ts";
|
|
9
|
+
export declare const SQL_DIALECTS: Readonly<Record<Dialect, SqlDialect>>;
|
|
10
|
+
/** The SQL dialect a dialect name selects. */
|
|
11
|
+
export declare function getSqlDialect(params: {
|
|
12
|
+
dialect: Dialect;
|
|
13
|
+
}): SqlDialect;
|
|
14
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/dialects/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAKhD,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAI9D,CAAC;AAEF,8CAA8C;AAC9C,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,UAAU,CAEtE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite dialect (bun:sqlite adapter lands in P4).
|
|
3
|
+
*
|
|
4
|
+
* Notes pinned by catalog cases:
|
|
5
|
+
* - OFFSET requires LIMIT → `LIMIT -1 OFFSET n`.
|
|
6
|
+
* - LIKE has no default escape character → explicit ` ESCAPE '\'` clause.
|
|
7
|
+
* - Case-insensitive matching uses LOWER()/LOWER() (default LIKE is only
|
|
8
|
+
* ASCII-case-insensitive, and we want deterministic semantics).
|
|
9
|
+
*/
|
|
10
|
+
import type { SqlDialect } from "../dialect.ts";
|
|
11
|
+
export declare const sqliteDialect: SqlDialect;
|
|
12
|
+
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/dialects/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,eAAO,MAAM,aAAa,EAAE,UAiD3B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vibeorm/sql — dialect-aware SQL layer for VibeORM v2.
|
|
3
|
+
*
|
|
4
|
+
* SQL AST + per-dialect renderers + capability tables. Every SQL-text decision
|
|
5
|
+
* lives in this package; see the root sql-catalog.md for the reviewable surface.
|
|
6
|
+
*/
|
|
7
|
+
export type { AggFn, AggRef, AggSelect, ColRef, ComparisonOp, DeleteStatement, InnerJoin, InsertStatement, JsonFilterOp, LateralJoin, ListSetOperation, OnConflictClause, OnConflictDoNothing, OnConflictUpdate, OrderByAggregate, OrderByColumn, OrderBySubquery, OrderTerm, RowNumberProjection, JsonParamCell, SelectExpr, SelectStatement, SetOperation, SetOperator, SqlExpr, SqlStatement, TableRef, UpdateStatement, } from "./ast.ts";
|
|
8
|
+
export { SQL_DEFAULT_CELL, isJsonParamCell, isListSetOperation, isSetOperation, isSqlDefaultCell, jsonParamCell, } from "./ast.ts";
|
|
9
|
+
export type { SqlDialect } from "./dialect.ts";
|
|
10
|
+
export { postgresDialect } from "./dialects/postgres.ts";
|
|
11
|
+
export { sqliteDialect } from "./dialects/sqlite.ts";
|
|
12
|
+
export { mysqlDialect } from "./dialects/mysql.ts";
|
|
13
|
+
export { SQL_DIALECTS, getSqlDialect } from "./dialects/registry.ts";
|
|
14
|
+
export { DIALECT_CAPABILITIES, MYSQL_CAPABILITIES, POSTGRES_CAPABILITIES, SQLITE_CAPABILITIES, } from "./capabilities.ts";
|
|
15
|
+
export { DIALECT_CODECS, MYSQL_CODECS, POSTGRES_CODECS, SQLITE_CODECS, decodeIsNoop, } from "./codecs.ts";
|
|
16
|
+
export type { CodecTable, ScalarCodec, WireFidelity } from "./codecs.ts";
|
|
17
|
+
export { renderExpr, renderFragment, renderStatement } from "./render.ts";
|
|
18
|
+
export type { RenderedQuery } from "./render.ts";
|
|
19
|
+
export { ParamCollector } from "./params.ts";
|
|
20
|
+
export { containsPattern, endsWithPattern, escapeGlobPattern, escapeLikePattern, startsWithPattern, strictMatchPattern } from "./like.ts";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,YAAY,EACV,KAAK,EACL,MAAM,EACN,SAAS,EACT,MAAM,EACN,YAAY,EACZ,eAAe,EACf,SAAS,EACT,eAAe,EACf,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,UAAU,EACV,eAAe,EACf,YAAY,EACZ,WAAW,EACX,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,aAAa,GACd,MAAM,UAAU,CAAC;AAIlB,YAAY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