@expressive/sql 0.5.0 → 0.7.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.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # @expressive/sql
2
2
 
3
- Entities on [`@expressive/mvc`](https://github.com/gabeklein/expressive-mvc) Model, stored in SQLite with nothing else installed. Re-exports [`@expressive/orm`](https://github.com/gabeklein/expressive-orm/tree/main/packages/orm): entities, field helpers, `Query` and a connection come from this one import. Full guide: [README](https://github.com/gabeklein/expressive-orm#readme).
3
+ Entities on [`@expressive/mvc`](https://github.com/gabeklein/expressive-mvc) Model, stored in SQLite with nothing else installed. Re-exports [`@expressive/orm`](https://github.com/gabeklein/expressive-orm/tree/main/packages/orm): entities, field helpers, `Query` and a connection come from this one import. Full guide: [README](https://github.com/gabeklein/expressive-orm#readme). Agent skill: [skills/expressive-sql](skills/expressive-sql/SKILL.md), shipped in the package with `expressive-orm`'s declared.
4
4
 
5
5
  ```sh
6
6
  npm install @expressive/sql @expressive/mvc
7
7
  ```
8
8
 
9
- SQLite is built into Bun (`bun:sqlite`) and Node 24 (`node:sqlite`). Elsewhere add one of `better-sqlite3`, `sqlite3` or `@libsql/client`; the first found is used.
9
+ SQLite is built into Bun (`bun:sqlite`) and Node 24 (`node:sqlite`). Elsewhere add one of `better-sqlite3`, `sqlite3` or `@libsql/client` (0.18 or later); the first found is used.
10
10
 
11
11
  ```ts
12
12
  import { Query, SQLiteConnection, Type, greaterThan, num, one, str } from '@expressive/sql';
@@ -42,12 +42,13 @@ await gabe.set({ name: "Gabriel" });
42
42
  await db.close();
43
43
  ```
44
44
 
45
- `SQLiteConnection.new(types, filename?)` binds the classes; awaiting it creates missing tables, adds missing columns and checks existing ones. SQLite cannot add a `unique` column or one defaulting to `"NOW"`; `sync` reports those. Omit `filename` for an in-memory database.
45
+ `SQLiteConnection.new(types, filename?)` binds the classes; awaiting it creates missing tables, adds missing columns and checks existing ones. SQLite cannot add a `unique` column or one defaulting to `"NOW"`; `sync` reports those. Omit `filename` for an in-memory database. In its place, pass a Cloudflare D1 binding, a libSQL client or a `libsql://` address - see [SQLite hosts](https://github.com/gabeklein/expressive-orm#sqlite-hosts).
46
46
 
47
47
  ## Also here
48
48
 
49
49
  - `Connection` - the SQL connection base: orm's floor implemented over `Query`, so a dialect supplies `prepare` (with a `Generator` subclass) and `sync`.
50
50
  - `Generator` - renders a `Query` builder as SQL.
51
+ - Driver seams - `Builder`, `DataTable`, `DataField`, `Parameter`, `Computed`, `QueryTemplate`, `Where` - import from `@expressive/orm/driver`. A dialect package lists `@expressive/orm` as a direct dependency, at the range this package depends on.
51
52
  - `StringColumn`, `NumericColumn`, `BooleanColumn`, `TimeColumn`, `ForeignColumn` - the column classes behind `str`, `num`, `bool`, `date` and `one`, carrying the SQL datatype vocabulary and its validation. See [Datatypes](https://github.com/gabeklein/expressive-orm#datatypes).
52
53
 
53
54
  SQLite has no live rows - neither `node:sqlite` nor `bun:sqlite` exposes an update hook. For those, use [`@expressive/postgres`](https://github.com/gabeklein/expressive-orm/tree/main/packages/postgres).
@@ -26,6 +26,7 @@ declare module '@expressive/orm' {
26
26
  }
27
27
  }
28
28
  }
29
+ /** Column class behind `bool()` on SQL - `boolean`, `integer`, or `text` / `varchar` with `either`. */
29
30
  declare class BooleanColumn extends bool.Type {
30
31
  type: bool.DataType;
31
32
  get datatype(): string;
@@ -1,6 +1,7 @@
1
1
  import { bool } from "@expressive/orm";
2
2
 
3
3
  //#region src/columns/Bool.ts
4
+ /** Column class behind `bool()` on SQL - `boolean`, `integer`, or `text` / `varchar` with `either`. */
4
5
  var BooleanColumn = class extends bool.Type {
5
6
  constructor(..._args) {
6
7
  super(..._args);
@@ -1 +1 @@
1
- {"version":3,"file":"Bool.js","names":[],"sources":["../../src/columns/Bool.ts"],"sourcesContent":["import { bool } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace bool {\n interface Boolean extends BooleanColumn {\n type: \"boolean\";\n }\n\n interface Integer extends BooleanColumn {\n type: \"integer\";\n }\n\n interface Text extends BooleanColumn {\n type: \"text\";\n either: readonly [true: string, false: string];\n }\n\n interface VarChar extends BooleanColumn {\n type: \"varchar\";\n either: readonly [true: string, false: string];\n }\n\n interface Types {\n default: Boolean;\n boolean: Boolean;\n integer: Integer;\n text: Text;\n varchar: VarChar;\n }\n }\n}\n\nexport class BooleanColumn extends bool.Type {\n type: bool.DataType = \"boolean\";\n\n get datatype() {\n const { type, either } = this;\n\n if (type === \"varchar\" && either) {\n const [TRUE, FALSE] = either.map(String);\n return `varchar(${Math.max(TRUE.length, FALSE.length)})`;\n }\n\n return type;\n }\n\n set(value: unknown) {\n const out = super.set(value);\n\n if (out == null || this.either || this.type !== \"boolean\")\n return out;\n\n return value as boolean;\n }\n}\n\nbool.Type = BooleanColumn;\n"],"mappings":";;;AAgCA,IAAa,gBAAb,cAAmC,KAAK,KAAK;;;cACrB;;CAEtB,IAAI,WAAW;EACb,MAAM,EAAE,MAAM,WAAW;AAEzB,MAAI,SAAS,aAAa,QAAQ;GAChC,MAAM,CAAC,MAAM,SAAS,OAAO,IAAI,OAAO;AACxC,UAAO,WAAW,KAAK,IAAI,KAAK,QAAQ,MAAM,OAAO,CAAC;;AAGxD,SAAO;;CAGT,IAAI,OAAgB;EAClB,MAAM,MAAM,MAAM,IAAI,MAAM;AAE5B,MAAI,OAAO,QAAQ,KAAK,UAAU,KAAK,SAAS,UAC9C,QAAO;AAET,SAAO;;;AAIX,KAAK,OAAO"}
1
+ {"version":3,"file":"Bool.js","names":[],"sources":["../../src/columns/Bool.ts"],"sourcesContent":["import { bool } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace bool {\n interface Boolean extends BooleanColumn {\n type: \"boolean\";\n }\n\n interface Integer extends BooleanColumn {\n type: \"integer\";\n }\n\n interface Text extends BooleanColumn {\n type: \"text\";\n either: readonly [true: string, false: string];\n }\n\n interface VarChar extends BooleanColumn {\n type: \"varchar\";\n either: readonly [true: string, false: string];\n }\n\n interface Types {\n default: Boolean;\n boolean: Boolean;\n integer: Integer;\n text: Text;\n varchar: VarChar;\n }\n }\n}\n\n/** Column class behind `bool()` on SQL - `boolean`, `integer`, or `text` / `varchar` with `either`. */\nexport class BooleanColumn extends bool.Type {\n type: bool.DataType = \"boolean\";\n\n get datatype() {\n const { type, either } = this;\n\n if (type === \"varchar\" && either) {\n const [TRUE, FALSE] = either.map(String);\n return `varchar(${Math.max(TRUE.length, FALSE.length)})`;\n }\n\n return type;\n }\n\n set(value: unknown) {\n const out = super.set(value);\n\n if (out == null || this.either || this.type !== \"boolean\")\n return out;\n\n return value as boolean;\n }\n}\n\nbool.Type = BooleanColumn;\n"],"mappings":";;;;AAiCA,IAAa,gBAAb,cAAmC,KAAK,KAAK;;;cACrB;;CAEtB,IAAI,WAAW;EACb,MAAM,EAAE,MAAM,WAAW;AAEzB,MAAI,SAAS,aAAa,QAAQ;GAChC,MAAM,CAAC,MAAM,SAAS,OAAO,IAAI,OAAO;AACxC,UAAO,WAAW,KAAK,IAAI,KAAK,QAAQ,MAAM,OAAO,CAAC;;AAGxD,SAAO;;CAGT,IAAI,OAAgB;EAClB,MAAM,MAAM,MAAM,IAAI,MAAM;AAE5B,MAAI,OAAO,QAAQ,KAAK,UAAU,KAAK,SAAS,UAC9C,QAAO;AAET,SAAO;;;AAIX,KAAK,OAAO"}
@@ -44,6 +44,11 @@ declare module '@expressive/orm' {
44
44
  }
45
45
  }
46
46
  }
47
+ /**
48
+ * Column class behind `num()` on SQL.
49
+ *
50
+ * Checks integer ranges and `numeric` precision and scale on write.
51
+ */
47
52
  declare class NumericColumn extends num.Type {
48
53
  type: num.DataType;
49
54
  get datatype(): string;
@@ -6,6 +6,11 @@ const RANGE = {
6
6
  integer: [-2147483648, 2147483647],
7
7
  bigint: [-Infinity, Infinity]
8
8
  };
9
+ /**
10
+ * Column class behind `num()` on SQL.
11
+ *
12
+ * Checks integer ranges and `numeric` precision and scale on write.
13
+ */
9
14
  var NumericColumn = class extends num.Type {
10
15
  constructor(..._args) {
11
16
  super(..._args);
@@ -1 +1 @@
1
- {"version":3,"file":"Num.js","names":[],"sources":["../../src/columns/Num.ts"],"sourcesContent":["import { num } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace num {\n interface Integer extends NumericColumn {\n type: \"integer\";\n }\n\n interface SmallInt extends NumericColumn {\n type: \"smallint\";\n }\n\n interface BigInt extends NumericColumn {\n type: \"bigint\";\n }\n\n interface Real extends NumericColumn {\n type: \"real\";\n }\n\n interface Float extends NumericColumn {\n type: \"float\";\n }\n\n interface Double extends NumericColumn {\n type: \"double\";\n }\n\n interface Numeric extends NumericColumn {\n type: \"numeric\";\n precision: number;\n scale: number;\n }\n\n interface Decimal extends NumericColumn {\n type: \"decimal\";\n precision: number;\n scale: number;\n }\n\n interface Types {\n default: Integer;\n integer: Integer;\n smallint: SmallInt;\n bigint: BigInt;\n real: Real;\n float: Float;\n double: Double;\n numeric: Numeric;\n decimal: Decimal;\n }\n }\n}\n\nconst RANGE: Record<string, [number, number]> = {\n smallint: [-32768, 32767],\n integer: [-2147483648, 2147483647],\n bigint: [-Infinity, Infinity]\n};\n\nexport class NumericColumn extends num.Type {\n type: num.DataType = \"integer\";\n\n get datatype() {\n return this.type === \"double\" ? \"double precision\" : super.datatype;\n }\n\n set(value: unknown) {\n const out = super.set(value);\n\n if (typeof value != \"number\")\n return out;\n\n const { type, precision, scale } = this;\n const range = RANGE[type];\n\n if (range) {\n const [min, max] = range;\n\n if (value !== Math.floor(value) || value < min || value > max)\n throw new Error(`Value ${value} out of range for ${type}.`);\n }\n else if (precision !== undefined) {\n const [whole, fraction = \"\"] = Math.abs(value).toString().split('.');\n\n if (whole.length + fraction.length > precision)\n throw new Error(`Value ${value} exceeds precision of ${precision}.`);\n\n if (scale !== undefined && fraction.length > scale)\n throw new Error(`Value ${value} exceeds scale of ${scale}.`);\n }\n\n return out;\n }\n}\n\nnum.Type = NumericColumn;\n"],"mappings":";;;AAsDA,MAAM,QAA0C;CAC9C,UAAU,CAAC,QAAQ,MAAM;CACzB,SAAS,CAAC,aAAa,WAAW;CAClC,QAAQ,CAAC,WAAW,SAAS;CAC9B;AAED,IAAa,gBAAb,cAAmC,IAAI,KAAK;;;cACrB;;CAErB,IAAI,WAAW;AACb,SAAO,KAAK,SAAS,WAAW,qBAAqB,MAAM;;CAG7D,IAAI,OAAgB;EAClB,MAAM,MAAM,MAAM,IAAI,MAAM;AAE5B,MAAI,OAAO,SAAS,SAClB,QAAO;EAET,MAAM,EAAE,MAAM,WAAW,UAAU;EACnC,MAAM,QAAQ,MAAM;AAEpB,MAAI,OAAO;GACT,MAAM,CAAC,KAAK,OAAO;AAEnB,OAAI,UAAU,KAAK,MAAM,MAAM,IAAI,QAAQ,OAAO,QAAQ,IACxD,OAAM,IAAI,MAAM,SAAS,MAAM,oBAAoB,KAAK,GAAG;aAEtD,cAAc,QAAW;GAChC,MAAM,CAAC,OAAO,WAAW,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,IAAI;AAEpE,OAAI,MAAM,SAAS,SAAS,SAAS,UACnC,OAAM,IAAI,MAAM,SAAS,MAAM,wBAAwB,UAAU,GAAG;AAEtE,OAAI,UAAU,UAAa,SAAS,SAAS,MAC3C,OAAM,IAAI,MAAM,SAAS,MAAM,oBAAoB,MAAM,GAAG;;AAGhE,SAAO;;;AAIX,IAAI,OAAO"}
1
+ {"version":3,"file":"Num.js","names":[],"sources":["../../src/columns/Num.ts"],"sourcesContent":["import { num } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace num {\n interface Integer extends NumericColumn {\n type: \"integer\";\n }\n\n interface SmallInt extends NumericColumn {\n type: \"smallint\";\n }\n\n interface BigInt extends NumericColumn {\n type: \"bigint\";\n }\n\n interface Real extends NumericColumn {\n type: \"real\";\n }\n\n interface Float extends NumericColumn {\n type: \"float\";\n }\n\n interface Double extends NumericColumn {\n type: \"double\";\n }\n\n interface Numeric extends NumericColumn {\n type: \"numeric\";\n precision: number;\n scale: number;\n }\n\n interface Decimal extends NumericColumn {\n type: \"decimal\";\n precision: number;\n scale: number;\n }\n\n interface Types {\n default: Integer;\n integer: Integer;\n smallint: SmallInt;\n bigint: BigInt;\n real: Real;\n float: Float;\n double: Double;\n numeric: Numeric;\n decimal: Decimal;\n }\n }\n}\n\nconst RANGE: Record<string, [number, number]> = {\n smallint: [-32768, 32767],\n integer: [-2147483648, 2147483647],\n bigint: [-Infinity, Infinity]\n};\n\n/**\n * Column class behind `num()` on SQL.\n *\n * Checks integer ranges and `numeric` precision and scale on write.\n */\nexport class NumericColumn extends num.Type {\n type: num.DataType = \"integer\";\n\n get datatype() {\n return this.type === \"double\" ? \"double precision\" : super.datatype;\n }\n\n set(value: unknown) {\n const out = super.set(value);\n\n if (typeof value != \"number\")\n return out;\n\n const { type, precision, scale } = this;\n const range = RANGE[type];\n\n if (range) {\n const [min, max] = range;\n\n if (value !== Math.floor(value) || value < min || value > max)\n throw new Error(`Value ${value} out of range for ${type}.`);\n }\n else if (precision !== undefined) {\n const [whole, fraction = \"\"] = Math.abs(value).toString().split('.');\n\n if (whole.length + fraction.length > precision)\n throw new Error(`Value ${value} exceeds precision of ${precision}.`);\n\n if (scale !== undefined && fraction.length > scale)\n throw new Error(`Value ${value} exceeds scale of ${scale}.`);\n }\n\n return out;\n }\n}\n\nnum.Type = NumericColumn;\n"],"mappings":";;;AAsDA,MAAM,QAA0C;CAC9C,UAAU,CAAC,QAAQ,MAAM;CACzB,SAAS,CAAC,aAAa,WAAW;CAClC,QAAQ,CAAC,WAAW,SAAS;CAC9B;;;;;;AAOD,IAAa,gBAAb,cAAmC,IAAI,KAAK;;;cACrB;;CAErB,IAAI,WAAW;AACb,SAAO,KAAK,SAAS,WAAW,qBAAqB,MAAM;;CAG7D,IAAI,OAAgB;EAClB,MAAM,MAAM,MAAM,IAAI,MAAM;AAE5B,MAAI,OAAO,SAAS,SAClB,QAAO;EAET,MAAM,EAAE,MAAM,WAAW,UAAU;EACnC,MAAM,QAAQ,MAAM;AAEpB,MAAI,OAAO;GACT,MAAM,CAAC,KAAK,OAAO;AAEnB,OAAI,UAAU,KAAK,MAAM,MAAM,IAAI,QAAQ,OAAO,QAAQ,IACxD,OAAM,IAAI,MAAM,SAAS,MAAM,oBAAoB,KAAK,GAAG;aAEtD,cAAc,QAAW;GAChC,MAAM,CAAC,OAAO,WAAW,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,IAAI;AAEpE,OAAI,MAAM,SAAS,SAAS,SAAS,UACnC,OAAM,IAAI,MAAM,SAAS,MAAM,wBAAwB,UAAU,GAAG;AAEtE,OAAI,UAAU,UAAa,SAAS,SAAS,MAC3C,OAAM,IAAI,MAAM,SAAS,MAAM,oBAAoB,MAAM,GAAG;;AAGhE,SAAO;;;AAIX,IAAI,OAAO"}
@@ -16,6 +16,7 @@ declare module '@expressive/orm' {
16
16
  }
17
17
  }
18
18
  }
19
+ /** Column class behind `one()` on SQL - an `integer` or `bigint` foreign key. */
19
20
  declare class ForeignColumn<T extends Type = Type> extends one.Type<T> {
20
21
  type: one.DataType;
21
22
  }
@@ -1,6 +1,7 @@
1
1
  import { one } from "@expressive/orm";
2
2
 
3
3
  //#region src/columns/One.ts
4
+ /** Column class behind `one()` on SQL - an `integer` or `bigint` foreign key. */
4
5
  var ForeignColumn = class extends one.Type {
5
6
  constructor(..._args) {
6
7
  super(..._args);
@@ -1 +1 @@
1
- {"version":3,"file":"One.js","names":[],"sources":["../../src/columns/One.ts"],"sourcesContent":["import { one, type Type } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace one {\n interface Integer<T extends Type = Type> extends ForeignColumn<T> {\n type: \"integer\";\n }\n\n interface BigInt<T extends Type = Type> extends ForeignColumn<T> {\n type: \"bigint\";\n }\n\n interface Types {\n default: Integer;\n integer: Integer;\n bigint: BigInt;\n }\n }\n}\n\nexport class ForeignColumn<T extends Type = Type> extends one.Type<T> {\n type: one.DataType = \"integer\";\n}\n\none.Type = ForeignColumn;\n"],"mappings":";;;AAoBA,IAAa,gBAAb,cAA0D,IAAI,KAAQ;;;cAC/C;;;AAGvB,IAAI,OAAO"}
1
+ {"version":3,"file":"One.js","names":[],"sources":["../../src/columns/One.ts"],"sourcesContent":["import { one, type Type } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace one {\n interface Integer<T extends Type = Type> extends ForeignColumn<T> {\n type: \"integer\";\n }\n\n interface BigInt<T extends Type = Type> extends ForeignColumn<T> {\n type: \"bigint\";\n }\n\n interface Types {\n default: Integer;\n integer: Integer;\n bigint: BigInt;\n }\n }\n}\n\n/** Column class behind `one()` on SQL - an `integer` or `bigint` foreign key. */\nexport class ForeignColumn<T extends Type = Type> extends one.Type<T> {\n type: one.DataType = \"integer\";\n}\n\none.Type = ForeignColumn;\n"],"mappings":";;;;AAqBA,IAAa,gBAAb,cAA0D,IAAI,KAAQ;;;cAC/C;;;AAGvB,IAAI,OAAO"}
@@ -26,6 +26,7 @@ declare module '@expressive/orm' {
26
26
  }
27
27
  }
28
28
  }
29
+ /** Column class behind `str()` on SQL - `text`, `varchar`, `char` or `uuid`. */
29
30
  declare class StringColumn extends str.Type {
30
31
  type: str.DataType;
31
32
  get datatype(): string;
@@ -1,6 +1,7 @@
1
1
  import { str } from "@expressive/orm";
2
2
 
3
3
  //#region src/columns/Str.ts
4
+ /** Column class behind `str()` on SQL - `text`, `varchar`, `char` or `uuid`. */
4
5
  var StringColumn = class extends str.Type {
5
6
  constructor(..._args) {
6
7
  super(..._args);
@@ -1 +1 @@
1
- {"version":3,"file":"Str.js","names":[],"sources":["../../src/columns/Str.ts"],"sourcesContent":["import { str } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace str {\n interface Text extends StringColumn {\n type: \"text\";\n }\n\n interface VarChar extends StringColumn {\n type: \"varchar\";\n length: number;\n }\n\n interface Char extends StringColumn {\n type: \"char\";\n length: number;\n }\n\n interface UUID extends StringColumn {\n type: \"uuid\";\n }\n\n interface Types {\n default: Text;\n text: Text;\n varchar: VarChar;\n char: Char;\n uuid: UUID;\n }\n }\n}\n\nexport class StringColumn extends str.Type {\n type: str.DataType = \"text\";\n\n get datatype() {\n let { type, length, collate } = this;\n\n if (type.endsWith(\"char\") && length)\n type += `(${length})`;\n\n if (collate)\n type += ` COLLATE \"${collate}\"`;\n\n return type;\n }\n}\n\nstr.Type = StringColumn;\n"],"mappings":";;;AAgCA,IAAa,eAAb,cAAkC,IAAI,KAAK;;;cACpB;;CAErB,IAAI,WAAW;EACb,IAAI,EAAE,MAAM,QAAQ,YAAY;AAEhC,MAAI,KAAK,SAAS,OAAO,IAAI,OAC3B,SAAQ,IAAI,OAAO;AAErB,MAAI,QACF,SAAQ,aAAa,QAAQ;AAE/B,SAAO;;;AAIX,IAAI,OAAO"}
1
+ {"version":3,"file":"Str.js","names":[],"sources":["../../src/columns/Str.ts"],"sourcesContent":["import { str } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace str {\n interface Text extends StringColumn {\n type: \"text\";\n }\n\n interface VarChar extends StringColumn {\n type: \"varchar\";\n length: number;\n }\n\n interface Char extends StringColumn {\n type: \"char\";\n length: number;\n }\n\n interface UUID extends StringColumn {\n type: \"uuid\";\n }\n\n interface Types {\n default: Text;\n text: Text;\n varchar: VarChar;\n char: Char;\n uuid: UUID;\n }\n }\n}\n\n/** Column class behind `str()` on SQL - `text`, `varchar`, `char` or `uuid`. */\nexport class StringColumn extends str.Type {\n type: str.DataType = \"text\";\n\n get datatype() {\n let { type, length, collate } = this;\n\n if (type.endsWith(\"char\") && length)\n type += `(${length})`;\n\n if (collate)\n type += ` COLLATE \"${collate}\"`;\n\n return type;\n }\n}\n\nstr.Type = StringColumn;\n"],"mappings":";;;;AAiCA,IAAa,eAAb,cAAkC,IAAI,KAAK;;;cACpB;;CAErB,IAAI,WAAW;EACb,IAAI,EAAE,MAAM,QAAQ,YAAY;AAEhC,MAAI,KAAK,SAAS,OAAO,IAAI,OAC3B,SAAQ,IAAI,OAAO;AAErB,MAAI,QACF,SAAQ,aAAa,QAAQ;AAE/B,SAAO;;;AAIX,IAAI,OAAO"}
@@ -36,6 +36,11 @@ declare module '@expressive/orm' {
36
36
  }
37
37
  }
38
38
  }
39
+ /**
40
+ * Column class behind `date()` on SQL.
41
+ *
42
+ * Stores a Date as `timestamp`, `date`, `time`, `ms`, `seconds`, `integer` or `text`.
43
+ */
39
44
  declare class TimeColumn extends date.Type {
40
45
  type: date.DataType;
41
46
  get datatype(): string;
@@ -1,6 +1,11 @@
1
1
  import { date } from "@expressive/orm";
2
2
 
3
3
  //#region src/columns/Time.ts
4
+ /**
5
+ * Column class behind `date()` on SQL.
6
+ *
7
+ * Stores a Date as `timestamp`, `date`, `time`, `ms`, `seconds`, `integer` or `text`.
8
+ */
4
9
  var TimeColumn = class extends date.Type {
5
10
  constructor(..._args) {
6
11
  super(..._args);
@@ -1 +1 @@
1
- {"version":3,"file":"Time.js","names":[],"sources":["../../src/columns/Time.ts"],"sourcesContent":["import { date } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace date {\n interface Timestamp extends TimeColumn {\n type: \"timestamp\";\n }\n\n interface Day extends TimeColumn {\n type: \"date\";\n }\n\n interface Time extends TimeColumn {\n type: \"time\";\n }\n\n interface Integer extends TimeColumn {\n type: \"integer\";\n }\n\n interface Text extends TimeColumn {\n type: \"text\";\n }\n\n interface Ms extends TimeColumn {\n type: \"ms\";\n }\n\n interface Seconds extends TimeColumn {\n type: \"seconds\";\n }\n\n interface Types {\n default: Timestamp;\n timestamp: Timestamp;\n date: Day;\n time: Time;\n integer: Integer;\n text: Text;\n ms: Ms;\n seconds: Seconds;\n }\n }\n}\n\nexport class TimeColumn extends date.Type {\n type: date.DataType = \"timestamp\";\n\n get datatype() {\n const { type } = this;\n\n return type === \"ms\" ? \"bigint\" : type === \"seconds\" ? \"integer\" : super.datatype;\n }\n\n get(value: unknown) {\n if (value == null)\n return undefined;\n\n if (this.type === \"ms\")\n return new Date(Number(value));\n\n if (typeof value === 'number')\n return new Date(value * 1000);\n\n if (typeof value === 'string' && this.type === \"date\") {\n const [year, month, day] = value.split('-').map(Number);\n return new Date(year, month - 1, day);\n }\n\n if (typeof value === 'string' && this.type === \"time\")\n return new Date(`1970-01-01T${value}Z`);\n\n if (typeof value === 'string' && /^\\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d(\\.\\d+)?$/.test(value))\n return new Date(value.replace(\" \", \"T\") + \"Z\");\n\n return new Date(value as string | Date);\n }\n\n set(value: unknown) {\n const iso = super.set(value);\n\n if (iso === undefined)\n return iso;\n\n const date = new Date(iso);\n\n if (this.type === \"ms\")\n return date.getTime();\n\n if (this.type === \"integer\" || this.type === \"seconds\")\n return Math.floor(date.getTime() / 1000);\n\n if (this.type === \"date\")\n return date.toISOString().slice(0, 10);\n\n if (this.type === \"time\")\n return date.toISOString().slice(11, 19);\n\n return iso;\n }\n}\n\ndate.Type = TimeColumn;\n"],"mappings":";;;AA6CA,IAAa,aAAb,cAAgC,KAAK,KAAK;;;cAClB;;CAEtB,IAAI,WAAW;EACb,MAAM,EAAE,SAAS;AAEjB,SAAO,SAAS,OAAO,WAAW,SAAS,YAAY,YAAY,MAAM;;CAG3E,IAAI,OAAgB;AAClB,MAAI,SAAS,KACX,QAAO;AAET,MAAI,KAAK,SAAS,KAChB,QAAO,IAAI,KAAK,OAAO,MAAM,CAAC;AAEhC,MAAI,OAAO,UAAU,SACnB,wBAAO,IAAI,KAAK,QAAQ,IAAK;AAE/B,MAAI,OAAO,UAAU,YAAY,KAAK,SAAS,QAAQ;GACrD,MAAM,CAAC,MAAM,OAAO,OAAO,MAAM,MAAM,IAAI,CAAC,IAAI,OAAO;AACvD,UAAO,IAAI,KAAK,MAAM,QAAQ,GAAG,IAAI;;AAGvC,MAAI,OAAO,UAAU,YAAY,KAAK,SAAS,OAC7C,wBAAO,IAAI,KAAK,cAAc,MAAM,GAAG;AAEzC,MAAI,OAAO,UAAU,YAAY,2CAA2C,KAAK,MAAM,CACrF,wBAAO,IAAI,KAAK,MAAM,QAAQ,KAAK,IAAI,GAAG,IAAI;AAEhD,SAAO,IAAI,KAAK,MAAuB;;CAGzC,IAAI,OAAgB;EAClB,MAAM,MAAM,MAAM,IAAI,MAAM;AAE5B,MAAI,QAAQ,OACV,QAAO;EAET,MAAM,OAAO,IAAI,KAAK,IAAI;AAE1B,MAAI,KAAK,SAAS,KAChB,QAAO,KAAK,SAAS;AAEvB,MAAI,KAAK,SAAS,aAAa,KAAK,SAAS,UAC3C,QAAO,KAAK,MAAM,KAAK,SAAS,GAAG,IAAK;AAE1C,MAAI,KAAK,SAAS,OAChB,QAAO,KAAK,aAAa,CAAC,MAAM,GAAG,GAAG;AAExC,MAAI,KAAK,SAAS,OAChB,QAAO,KAAK,aAAa,CAAC,MAAM,IAAI,GAAG;AAEzC,SAAO;;;AAIX,KAAK,OAAO"}
1
+ {"version":3,"file":"Time.js","names":[],"sources":["../../src/columns/Time.ts"],"sourcesContent":["import { date } from '@expressive/orm';\n\ndeclare module '@expressive/orm' {\n namespace date {\n interface Timestamp extends TimeColumn {\n type: \"timestamp\";\n }\n\n interface Day extends TimeColumn {\n type: \"date\";\n }\n\n interface Time extends TimeColumn {\n type: \"time\";\n }\n\n interface Integer extends TimeColumn {\n type: \"integer\";\n }\n\n interface Text extends TimeColumn {\n type: \"text\";\n }\n\n interface Ms extends TimeColumn {\n type: \"ms\";\n }\n\n interface Seconds extends TimeColumn {\n type: \"seconds\";\n }\n\n interface Types {\n default: Timestamp;\n timestamp: Timestamp;\n date: Day;\n time: Time;\n integer: Integer;\n text: Text;\n ms: Ms;\n seconds: Seconds;\n }\n }\n}\n\n/**\n * Column class behind `date()` on SQL.\n *\n * Stores a Date as `timestamp`, `date`, `time`, `ms`, `seconds`, `integer` or `text`.\n */\nexport class TimeColumn extends date.Type {\n type: date.DataType = \"timestamp\";\n\n get datatype() {\n const { type } = this;\n\n return type === \"ms\" ? \"bigint\" : type === \"seconds\" ? \"integer\" : super.datatype;\n }\n\n get(value: unknown) {\n if (value == null)\n return undefined;\n\n if (this.type === \"ms\")\n return new Date(Number(value));\n\n if (typeof value === 'number')\n return new Date(value * 1000);\n\n if (typeof value === 'string' && this.type === \"date\") {\n const [year, month, day] = value.split('-').map(Number);\n return new Date(year, month - 1, day);\n }\n\n if (typeof value === 'string' && this.type === \"time\")\n return new Date(`1970-01-01T${value}Z`);\n\n if (typeof value === 'string' && /^\\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d(\\.\\d+)?$/.test(value))\n return new Date(value.replace(\" \", \"T\") + \"Z\");\n\n return new Date(value as string | Date);\n }\n\n set(value: unknown) {\n const iso = super.set(value);\n\n if (iso === undefined)\n return iso;\n\n const date = new Date(iso);\n\n if (this.type === \"ms\")\n return date.getTime();\n\n if (this.type === \"integer\" || this.type === \"seconds\")\n return Math.floor(date.getTime() / 1000);\n\n if (this.type === \"date\")\n return date.toISOString().slice(0, 10);\n\n if (this.type === \"time\")\n return date.toISOString().slice(11, 19);\n\n return iso;\n }\n}\n\ndate.Type = TimeColumn;\n"],"mappings":";;;;;;;;AAkDA,IAAa,aAAb,cAAgC,KAAK,KAAK;;;cAClB;;CAEtB,IAAI,WAAW;EACb,MAAM,EAAE,SAAS;AAEjB,SAAO,SAAS,OAAO,WAAW,SAAS,YAAY,YAAY,MAAM;;CAG3E,IAAI,OAAgB;AAClB,MAAI,SAAS,KACX,QAAO;AAET,MAAI,KAAK,SAAS,KAChB,QAAO,IAAI,KAAK,OAAO,MAAM,CAAC;AAEhC,MAAI,OAAO,UAAU,SACnB,wBAAO,IAAI,KAAK,QAAQ,IAAK;AAE/B,MAAI,OAAO,UAAU,YAAY,KAAK,SAAS,QAAQ;GACrD,MAAM,CAAC,MAAM,OAAO,OAAO,MAAM,MAAM,IAAI,CAAC,IAAI,OAAO;AACvD,UAAO,IAAI,KAAK,MAAM,QAAQ,GAAG,IAAI;;AAGvC,MAAI,OAAO,UAAU,YAAY,KAAK,SAAS,OAC7C,wBAAO,IAAI,KAAK,cAAc,MAAM,GAAG;AAEzC,MAAI,OAAO,UAAU,YAAY,2CAA2C,KAAK,MAAM,CACrF,wBAAO,IAAI,KAAK,MAAM,QAAQ,KAAK,IAAI,GAAG,IAAI;AAEhD,SAAO,IAAI,KAAK,MAAuB;;CAGzC,IAAI,OAAgB;EAClB,MAAM,MAAM,MAAM,IAAI,MAAM;AAE5B,MAAI,QAAQ,OACV,QAAO;EAET,MAAM,OAAO,IAAI,KAAK,IAAI;AAE1B,MAAI,KAAK,SAAS,KAChB,QAAO,KAAK,SAAS;AAEvB,MAAI,KAAK,SAAS,aAAa,KAAK,SAAS,UAC3C,QAAO,KAAK,MAAM,KAAK,SAAS,GAAG,IAAK;AAE1C,MAAI,KAAK,SAAS,OAChB,QAAO,KAAK,aAAa,CAAC,MAAM,GAAG,GAAG;AAExC,MAAI,KAAK,SAAS,OAChB,QAAO,KAAK,aAAa,CAAC,MAAM,IAAI,GAAG;AAEzC,SAAO;;;AAIX,KAAK,OAAO"}
@@ -1,4 +1,5 @@
1
- import { Builder, Connection as Connection$1, Type } from "@expressive/orm";
1
+ import { Connection as Connection$1, Type } from "@expressive/orm";
2
+ import { Builder } from "@expressive/orm/driver";
2
3
 
3
4
  //#region src/connection/Connection.d.ts
4
5
  declare namespace Connection {
@@ -7,32 +8,49 @@ declare namespace Connection {
7
8
  type Change = Connection$1.Change;
8
9
  type Conflict = Connection$1.Conflict;
9
10
  type Key = Connection$1.Key;
10
- type Transaction = Connection$1.Journal & {
11
- session?: unknown;
12
- };
13
- type Step = {
11
+ /** An open transaction's journal. */
12
+ type Transaction = Connection$1.Journal;
13
+ /** One change `sync` would make. */
14
+ interface Step {
14
15
  table: string;
16
+ /** Column the step adds or indexes. Absent for a table step. */
15
17
  column?: string;
18
+ /** What it does, like `create table user`. */
16
19
  action: string;
20
+ /** The mismatch it resolves - what `sync(false)` reports. */
17
21
  reason: string;
22
+ /** Statements applying it. */
18
23
  sql: string[];
19
- };
20
- type Plan = {
24
+ }
25
+ /** What `sync` would do, and what stops it. */
26
+ interface Plan {
21
27
  steps: Step[];
28
+ /** Mismatches `sync` cannot fix. Any makes it throw. */
22
29
  problems: string[];
23
- };
30
+ }
24
31
  }
32
+ /**
33
+ * Base class of a SQL driver - implements orm's floor as queries through `prepare`.
34
+ *
35
+ * The floor is `select`, `insert`, `update` and `remove`.
36
+ *
37
+ * A dialect supplies `schema`, `prepare`, `sync` and `plan`, and `transact` to enable `transaction`.
38
+ * Each statement throws when no bound or loaded class owns its table.
39
+ */
25
40
  declare abstract class Connection extends Connection$1 {
26
- _active?: Promise<void>;
41
+ /** DDL creating every bound class's table and indexes. */
27
42
  abstract get schema(): string;
43
+ /**
44
+ * Bring the database in line with the bound classes, then mark the connection ready.
45
+ *
46
+ * Creates missing tables, columns and indexes. `fix` false changes nothing and throws for anything missing.
47
+ * `force` also converts columns whose type or nullability drifted. Throws for any problem `plan` reports.
48
+ */
28
49
  abstract sync(fix?: boolean, force?: boolean): Promise<this>;
50
+ /** List what `sync` would change, and what it could not, without applying anything. */
29
51
  abstract plan(force?: boolean): Promise<Connection.Plan>;
52
+ /** Compile a `Query` builder to a statement in this dialect. */
30
53
  abstract prepare(builder: Builder): Builder.Statement;
31
- protected transact?<T>(fn: () => Promise<T>): Promise<T>;
32
- _journal(): Connection.Transaction | undefined;
33
- transaction<T>(fn: () => T | Promise<T>): Promise<T>;
34
- protected lock(): Promise<() => void>;
35
- protected idle(): Promise<void>;
36
54
  select(table: string, constraints: Type.Constraint[], limit?: number, offset?: number): Promise<Record<string, any>[]>;
37
55
  insert(table: string, data: Record<string, any>, returns?: boolean, conflict?: Connection.Conflict): Promise<any>;
38
56
  update(table: string, id: Connection.Key, data: Record<string, any>): Promise<void>;
@@ -3,60 +3,22 @@ import "../columns/Num.js";
3
3
  import "../columns/One.js";
4
4
  import "../columns/Str.js";
5
5
  import "../columns/Time.js";
6
- import { Builder, Connection as Connection$1, Parameter } from "@expressive/orm";
6
+ import { Connection as Connection$1 } from "@expressive/orm";
7
+ import { Builder, Parameter } from "@expressive/orm/driver";
7
8
 
8
9
  //#region src/connection/Connection.ts
9
- let storage;
10
- let context;
11
- function hooks(name) {
12
- return import(name);
13
- }
14
- function scope() {
15
- return storage ||= hooks("node:async_hooks").then(({ AsyncLocalStorage }) => context = new AsyncLocalStorage(), () => {
16
- storage = void 0;
17
- throw new Error("Transactions need AsyncLocalStorage, which this runtime does not provide.");
18
- });
19
- }
20
10
  function ref({ schema, table }) {
21
11
  return schema ? `${schema}.${table}` : table;
22
12
  }
13
+ /**
14
+ * Base class of a SQL driver - implements orm's floor as queries through `prepare`.
15
+ *
16
+ * The floor is `select`, `insert`, `update` and `remove`.
17
+ *
18
+ * A dialect supplies `schema`, `prepare`, `sync` and `plan`, and `transact` to enable `transaction`.
19
+ * Each statement throws when no bound or loaded class owns its table.
20
+ */
23
21
  var Connection = class extends Connection$1 {
24
- _journal() {
25
- return context?.getStore()?.get(this);
26
- }
27
- async transaction(fn) {
28
- if (!this.transact) throw new Error(`${this.constructor.name} does not support transactions.`);
29
- const storage = await scope();
30
- const outer = storage.getStore();
31
- if (outer?.has(this)) return fn();
32
- const release = await this.lock();
33
- const journal = {
34
- undo: [],
35
- done: []
36
- };
37
- try {
38
- const result = await storage.run(new Map(outer).set(this, journal), () => this.transact(async () => fn()));
39
- journal.done.forEach((apply) => apply());
40
- return result;
41
- } catch (error) {
42
- journal.undo.reverse().forEach((apply) => apply());
43
- throw error;
44
- } finally {
45
- release();
46
- }
47
- }
48
- async lock() {
49
- while (this._active) await this._active;
50
- let release;
51
- this._active = new Promise((resolve) => release = resolve);
52
- return () => {
53
- this._active = void 0;
54
- release();
55
- };
56
- }
57
- async idle() {
58
- while (this._active && !this._journal()) await this._active;
59
- }
60
22
  async select(table, constraints, limit, offset) {
61
23
  const { builder, target, bind, run } = statement(this, table);
62
24
  for (const [column, op, value] of constraints) {
@@ -1 +1 @@
1
- {"version":3,"file":"Connection.js","names":["Base"],"sources":["../../src/connection/Connection.ts"],"sourcesContent":["import '../columns/Bool';\nimport '../columns/Num';\nimport '../columns/One';\nimport '../columns/Str';\nimport '../columns/Time';\n\nimport { Builder, Connection as Base, Field, Parameter, Query, Type } from '@expressive/orm';\n\ndeclare namespace Connection {\n type Types = Base.Types;\n\n type Ready<T extends Connection = Connection> = Base.Ready<T>;\n\n type Change = Base.Change;\n\n type Conflict = Base.Conflict;\n\n type Key = Base.Key;\n\n type Transaction = Base.Journal & {\n session?: unknown;\n };\n\n type Step = {\n table: string;\n column?: string;\n action: string;\n reason: string;\n sql: string[];\n };\n\n type Plan = {\n steps: Step[];\n problems: string[];\n };\n}\n\ntype Scope = Map<Connection, Connection.Transaction>;\n\nlet storage: Promise<import('node:async_hooks').AsyncLocalStorage<Scope>> | undefined;\nlet context: import('node:async_hooks').AsyncLocalStorage<Scope> | undefined;\n\nfunction hooks(name: string): Promise<typeof import('node:async_hooks')> {\n return import(name);\n}\n\nfunction scope(){\n return storage ||= hooks(\"node:async_hooks\").then(\n ({ AsyncLocalStorage }) => context = new AsyncLocalStorage<Scope>(),\n () => {\n storage = undefined;\n throw new Error(\"Transactions need AsyncLocalStorage, which this runtime does not provide.\");\n }\n );\n}\n\nfunction ref({ schema, table }: Query.Table){\n return schema ? `${schema}.${table}` : table;\n}\n\nabstract class Connection extends Base {\n _active?: Promise<void>;\n\n abstract get schema(): string;\n\n abstract sync(fix?: boolean, force?: boolean): Promise<this>;\n\n abstract plan(force?: boolean): Promise<Connection.Plan>;\n\n abstract prepare(builder: Builder): Builder.Statement;\n\n protected transact?<T>(fn: () => Promise<T>): Promise<T>;\n\n _journal(){\n return context?.getStore()?.get(this);\n }\n\n async transaction<T>(fn: () => T | Promise<T>): Promise<T> {\n if (!this.transact)\n throw new Error(`${this.constructor.name} does not support transactions.`);\n\n const storage = await scope();\n const outer = storage.getStore();\n\n if (outer?.has(this))\n return fn();\n\n const release = await this.lock();\n const journal: Connection.Transaction = { undo: [], done: [] };\n\n try {\n const result = await storage.run(new Map(outer).set(this, journal), () => this.transact!(async () => fn()));\n\n journal.done.forEach(apply => apply());\n\n return result;\n }\n catch (error) {\n journal.undo.reverse().forEach(apply => apply());\n throw error;\n }\n finally {\n release();\n }\n }\n\n protected async lock(){\n while (this._active)\n await this._active;\n\n let release!: () => void;\n\n this._active = new Promise(resolve => release = resolve);\n\n return () => {\n this._active = undefined;\n release();\n };\n }\n\n protected async idle(){\n while (this._active && !this._journal())\n await this._active;\n }\n\n async select(table: string, constraints: Type.Constraint[], limit?: number, offset?: number){\n const { builder, target, bind, run } = statement(this, table);\n\n for (const [column, op, value] of constraints) {\n const field = lookup(target, column);\n\n if (op === 'asc' || op === 'desc')\n builder.order.set(field, op);\n else if (op === 'IS NULL')\n builder.filters.add(field, '=', null);\n else if (op === 'IS NOT NULL')\n builder.filters.add(field, '<>', null);\n else if (value === null)\n builder.filters.add(field, op, null);\n else\n builder.filters.add(field, op, Array.isArray(value) ? value.map(bind) : bind(value));\n }\n\n builder.limit = limit;\n builder.offset = offset;\n builder.commit(target.proxy);\n\n const rows = await this.prepare(builder).all(run());\n\n return rows.map(raw => decode(builder, raw));\n }\n\n async insert(table: string, data: Record<string, any>, returns?: boolean, conflict?: Connection.Conflict){\n const { builder, target, bind, run } = statement(this, table);\n const values: Builder.Insert = new Map();\n\n for (const field of target.fields.values())\n if (field.column in data)\n values.set(field, bind(data[field.column]));\n\n builder.inserts.set(target, values);\n\n if (conflict)\n builder.conflict = {\n on: conflict.on.map(column => lookup(target, column)),\n update: conflict.update?.map(column => lookup(target, column)),\n set: new Map(Object.entries(conflict.set || {}).map(([column, value]) => [lookup(target, column), bind(value)]))\n };\n\n if (!returns)\n return this.prepare(builder).run(run());\n\n builder.commit(target.proxy);\n\n const [row] = await this.prepare(builder).all(run());\n\n return row && decode(builder, row);\n }\n\n async update(table: string, id: Connection.Key, data: Record<string, any>){\n const { builder, target, bind, run } = statement(this, table);\n const values: Builder.Insert = new Map();\n\n for (const column in data)\n values.set(lookup(target, column), bind(data[column]));\n\n builder.updates.set(target, values);\n identify(builder, target, id, bind);\n\n await this.prepare(builder).run(run());\n }\n\n async remove(table: string, id: Connection.Key){\n const { builder, target, bind, run } = statement(this, table);\n\n builder.deletes.add(target);\n identify(builder, target, id, bind);\n\n await this.prepare(builder).run(run());\n }\n}\n\nfunction identify(builder: Builder, target: Builder.ITable, id: Connection.Key, bind: (value: unknown) => Parameter){\n const { parts } = target.fields.get(\"id\")!;\n\n if (parts)\n parts.forEach((part, i) => builder.filters.add(lookup(target, part.column), '=', bind((id as unknown[])[i])));\n else\n builder.filters.add(target.fields.get(\"id\")!, '=', bind(id));\n}\n\nfunction statement(connection: Connection, table: string){\n const type = [...connection.using, ...connection._loaded.keys()].find(type => ref(type) === table);\n\n if (!type)\n throw new Error(`Table ${table} is not used by this connection.`);\n\n const builder = new Builder();\n const target = builder.tables.get(builder.use(type))!;\n const params: unknown[] = [];\n\n return {\n builder,\n target,\n bind(value: unknown){\n const param = new Parameter(params.length);\n\n params.push(value);\n builder.params.push(param);\n\n return param;\n },\n run: () => builder.accept(params)\n };\n}\n\nfunction lookup(table: Builder.ITable, column: string){\n for (const field of table.fields.values())\n if (field.column === column)\n return field;\n\n throw new Error(`Column ${column} does not exist in ${table.name}.`);\n}\n\nfunction decode(builder: Builder, raw: Record<string, any>){\n const row: Record<string, any> = {};\n\n (builder.returns as Map<string, Field>).forEach((field, key) => {\n row[field.column] = raw[key];\n });\n\n return row;\n}\n\nexport { Connection };\n"],"mappings":";;;;;;;;AAuCA,IAAI;AACJ,IAAI;AAEJ,SAAS,MAAM,MAA0D;AACvE,QAAO,OAAO;;AAGhB,SAAS,QAAO;AACd,QAAO,YAAY,MAAM,mBAAmB,CAAC,MAC1C,EAAE,wBAAwB,UAAU,IAAI,mBAA0B,QAC7D;AACJ,YAAU;AACV,QAAM,IAAI,MAAM,4EAA4E;GAE/F;;AAGH,SAAS,IAAI,EAAE,QAAQ,SAAqB;AAC1C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CAC7B,MAAM,SAAS,QAAQ,OAAO,IAAI,QAAQ,IAAI,KAAK,CAAC;CACpD,MAAM,SAAoB,EAAE;AAE5B,QAAO;EACL;EACA;EACA,KAAK,OAAe;GAClB,MAAM,QAAQ,IAAI,UAAU,OAAO,OAAO;AAE1C,UAAO,KAAK,MAAM;AAClB,WAAQ,OAAO,KAAK,MAAM;AAE1B,UAAO;;EAET,WAAW,QAAQ,OAAO,OAAO;EAClC;;AAGH,SAAS,OAAO,OAAuB,QAAe;AACpD,MAAK,MAAM,SAAS,MAAM,OAAO,QAAQ,CACvC,KAAI,MAAM,WAAW,OACnB,QAAO;AAEX,OAAM,IAAI,MAAM,UAAU,OAAO,qBAAqB,MAAM,KAAK,GAAG;;AAGtE,SAAS,OAAO,SAAkB,KAAyB;CACzD,MAAM,MAA2B,EAAE;AAEnC,CAAC,QAAQ,QAA+B,SAAS,OAAO,QAAQ;AAC9D,MAAI,MAAM,UAAU,IAAI;GACxB;AAEF,QAAO"}
1
+ {"version":3,"file":"Connection.js","names":["Base"],"sources":["../../src/connection/Connection.ts"],"sourcesContent":["import '../columns/Bool';\nimport '../columns/Num';\nimport '../columns/One';\nimport '../columns/Str';\nimport '../columns/Time';\n\nimport { Connection as Base, Field, Query, Type } from '@expressive/orm';\nimport { Builder, Parameter } from '@expressive/orm/driver';\n\ndeclare namespace Connection {\n type Types = Base.Types;\n\n type Ready<T extends Connection = Connection> = Base.Ready<T>;\n\n type Change = Base.Change;\n\n type Conflict = Base.Conflict;\n\n type Key = Base.Key;\n\n /** An open transaction's journal. */\n type Transaction = Base.Journal;\n\n /** One change `sync` would make. */\n interface Step {\n table: string;\n /** Column the step adds or indexes. Absent for a table step. */\n column?: string;\n /** What it does, like `create table user`. */\n action: string;\n /** The mismatch it resolves - what `sync(false)` reports. */\n reason: string;\n /** Statements applying it. */\n sql: string[];\n }\n\n /** What `sync` would do, and what stops it. */\n interface Plan {\n steps: Step[];\n /** Mismatches `sync` cannot fix. Any makes it throw. */\n problems: string[];\n }\n}\n\nfunction ref({ schema, table }: Query.Table){\n return schema ? `${schema}.${table}` : table;\n}\n\n/**\n * Base class of a SQL driver - implements orm's floor as queries through `prepare`.\n *\n * The floor is `select`, `insert`, `update` and `remove`.\n *\n * A dialect supplies `schema`, `prepare`, `sync` and `plan`, and `transact` to enable `transaction`.\n * Each statement throws when no bound or loaded class owns its table.\n */\nabstract class Connection extends Base {\n /** DDL creating every bound class's table and indexes. */\n abstract get schema(): string;\n\n /**\n * Bring the database in line with the bound classes, then mark the connection ready.\n *\n * Creates missing tables, columns and indexes. `fix` false changes nothing and throws for anything missing.\n * `force` also converts columns whose type or nullability drifted. Throws for any problem `plan` reports.\n */\n abstract sync(fix?: boolean, force?: boolean): Promise<this>;\n\n /** List what `sync` would change, and what it could not, without applying anything. */\n abstract plan(force?: boolean): Promise<Connection.Plan>;\n\n /** Compile a `Query` builder to a statement in this dialect. */\n abstract prepare(builder: Builder): Builder.Statement;\n\n async select(table: string, constraints: Type.Constraint[], limit?: number, offset?: number){\n const { builder, target, bind, run } = statement(this, table);\n\n for (const [column, op, value] of constraints) {\n const field = lookup(target, column);\n\n if (op === 'asc' || op === 'desc')\n builder.order.set(field, op);\n else if (op === 'IS NULL')\n builder.filters.add(field, '=', null);\n else if (op === 'IS NOT NULL')\n builder.filters.add(field, '<>', null);\n else if (value === null)\n builder.filters.add(field, op, null);\n else\n builder.filters.add(field, op, Array.isArray(value) ? value.map(bind) : bind(value));\n }\n\n builder.limit = limit;\n builder.offset = offset;\n builder.commit(target.proxy);\n\n const rows = await this.prepare(builder).all(run());\n\n return rows.map(raw => decode(builder, raw));\n }\n\n async insert(table: string, data: Record<string, any>, returns?: boolean, conflict?: Connection.Conflict){\n const { builder, target, bind, run } = statement(this, table);\n const values: Builder.Insert = new Map();\n\n for (const field of target.fields.values())\n if (field.column in data)\n values.set(field, bind(data[field.column]));\n\n builder.inserts.set(target, values);\n\n if (conflict)\n builder.conflict = {\n on: conflict.on.map(column => lookup(target, column)),\n update: conflict.update?.map(column => lookup(target, column)),\n set: new Map(Object.entries(conflict.set || {}).map(([column, value]) => [lookup(target, column), bind(value)]))\n };\n\n if (!returns)\n return this.prepare(builder).run(run());\n\n builder.commit(target.proxy);\n\n const [row] = await this.prepare(builder).all(run());\n\n return row && decode(builder, row);\n }\n\n async update(table: string, id: Connection.Key, data: Record<string, any>){\n const { builder, target, bind, run } = statement(this, table);\n const values: Builder.Insert = new Map();\n\n for (const column in data)\n values.set(lookup(target, column), bind(data[column]));\n\n builder.updates.set(target, values);\n identify(builder, target, id, bind);\n\n await this.prepare(builder).run(run());\n }\n\n async remove(table: string, id: Connection.Key){\n const { builder, target, bind, run } = statement(this, table);\n\n builder.deletes.add(target);\n identify(builder, target, id, bind);\n\n await this.prepare(builder).run(run());\n }\n}\n\nfunction identify(builder: Builder, target: Builder.ITable, id: Connection.Key, bind: (value: unknown) => Parameter){\n const { parts } = target.fields.get(\"id\")!;\n\n if (parts)\n parts.forEach((part, i) => builder.filters.add(lookup(target, part.column), '=', bind((id as unknown[])[i])));\n else\n builder.filters.add(target.fields.get(\"id\")!, '=', bind(id));\n}\n\nfunction statement(connection: Connection, table: string){\n const type = [...connection.using, ...connection._loaded.keys()].find(type => ref(type) === table);\n\n if (!type)\n throw new Error(`Table ${table} is not used by this connection.`);\n\n const builder = new Builder();\n const target = builder.tables.get(builder.use(type))!;\n const params: unknown[] = [];\n\n return {\n builder,\n target,\n bind(value: unknown){\n const param = new Parameter(params.length);\n\n params.push(value);\n builder.params.push(param);\n\n return param;\n },\n run: () => builder.accept(params)\n };\n}\n\nfunction lookup(table: Builder.ITable, column: string){\n for (const field of table.fields.values())\n if (field.column === column)\n return field;\n\n throw new Error(`Column ${column} does not exist in ${table.name}.`);\n}\n\nfunction decode(builder: Builder, raw: Record<string, any>){\n const row: Record<string, any> = {};\n\n (builder.returns as Map<string, Field>).forEach((field, key) => {\n row[field.column] = raw[key];\n });\n\n return row;\n}\n\nexport { Connection };\n"],"mappings":";;;;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,QAAQ,KAAK,OAAO,EAAE,KAAK,KAAM,GAAiB,GAAG,CAAC,CAAC;KAE7G,SAAQ,QAAQ,IAAI,OAAO,OAAO,IAAI,KAAK,EAAG,KAAK,KAAK,GAAG,CAAC;;AAGhE,SAAS,UAAU,YAAwB,OAAc;CACvD,MAAM,OAAO,CAAC,GAAG,WAAW,OAAO,GAAG,WAAW,QAAQ,MAAM,CAAC,CAAC,MAAK,SAAQ,IAAI,KAAK,KAAK,MAAM;AAElG,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,SAAS,MAAM,kCAAkC;CAEnE,MAAM,UAAU,IAAI,SAAS;CAC7B,MAAM,SAAS,QAAQ,OAAO,IAAI,QAAQ,IAAI,KAAK,CAAC;CACpD,MAAM,SAAoB,EAAE;AAE5B,QAAO;EACL;EACA;EACA,KAAK,OAAe;GAClB,MAAM,QAAQ,IAAI,UAAU,OAAO,OAAO;AAE1C,UAAO,KAAK,MAAM;AAClB,WAAQ,OAAO,KAAK,MAAM;AAE1B,UAAO;;EAET,WAAW,QAAQ,OAAO,OAAO;EAClC;;AAGH,SAAS,OAAO,OAAuB,QAAe;AACpD,MAAK,MAAM,SAAS,MAAM,OAAO,QAAQ,CACvC,KAAI,MAAM,WAAW,OACnB,QAAO;AAEX,OAAM,IAAI,MAAM,UAAU,OAAO,qBAAqB,MAAM,KAAK,GAAG;;AAGtE,SAAS,OAAO,SAAkB,KAAyB;CACzD,MAAM,MAA2B,EAAE;AAEnC,CAAC,QAAQ,QAA+B,SAAS,OAAO,QAAQ;AAC9D,MAAI,MAAM,UAAU,IAAI;GACxB;AAEF,QAAO"}
@@ -1,30 +1,66 @@
1
- import { Builder, Computed, DataTable, Field, Parameter } from "@expressive/orm";
1
+ import { Field } from "@expressive/orm";
2
+ import { Builder, Computed, DataTable, Parameter } from "@expressive/orm/driver";
2
3
 
3
4
  //#region src/connection/Generator.d.ts
5
+ /**
6
+ * Renders a `Query` builder as one SQL statement - `String(generator)`.
7
+ *
8
+ * A dialect subclasses it and overrides the protected hooks. Literals render inline, escaped; parameters bind.
9
+ */
4
10
  declare class Generator {
5
11
  query: Builder;
6
12
  constructor(query: Builder);
7
13
  toString(): string;
14
+ /** Quote an identifier, each dotted part on its own. */
8
15
  escape(name: unknown): string;
9
- protected insert(): false | (string | false | (string | undefined)[] | undefined)[];
16
+ /** `INSERT INTO`, or `false` when the query inserts nothing. */
17
+ protected insert(): false | unknown[];
18
+ /** Order an insert's data CTE, target and select - for a dialect placing `WITH` elsewhere. */
19
+ protected insertWith(cte: string | undefined, into: unknown[], select: unknown[]): unknown[];
20
+ /** `ON CONFLICT` clause of an upsert. */
10
21
  protected upsert(): string[] | undefined;
22
+ /** `RETURNING` clause of an insert that selects. */
11
23
  protected returning(): string | undefined;
24
+ /** `WITH` clause over the query's data tables. */
12
25
  protected with(): string | undefined;
26
+ /** A value - `now`, a reference, or a literal. */
13
27
  protected value(input: unknown, field?: Field): string;
28
+ /** A literal - every literal in values, `SET` and `WHERE` passes through it. */
29
+ protected literal(value: unknown): string;
30
+ /** A table with its alias - for `FROM`, joins, `UPDATE` and `DELETE`. */
31
+ protected table({
32
+ name,
33
+ alias
34
+ }: Builder.ITable): string;
35
+ /** The current time - `CURRENT_TIMESTAMP`; a dialect renders it per `field`'s storage. */
14
36
  protected now(_field?: Field): string;
37
+ /** Select a data table's rows out of its bound parameter. The base throws - a dialect implements it. */
15
38
  protected jsonTable(_table: DataTable): string;
39
+ /** An arithmetic expression, parenthesized by operator rank. */
16
40
  protected computed(from: Computed<unknown>): string;
41
+ /** `JOIN` clauses for every table but `main`. Throws for a table without a join condition. */
17
42
  protected joins(main: Builder.ITable): string | undefined;
43
+ /** `SET` clause of an update. Throws without values. */
18
44
  protected set(updates: Map<Builder.ITable, Builder.Insert>): string;
45
+ /** `UPDATE` head. Throws when the query updates more than one table. */
19
46
  protected update(): (string | undefined)[] | undefined;
47
+ /** `DELETE FROM` head. */
20
48
  protected delete(): (string | false | undefined)[] | undefined;
49
+ /** A column, parameter, data column, raw template or expression. */
21
50
  protected reference(from: unknown): string;
22
- protected select(): (string | (string | undefined)[] | undefined)[];
23
- protected from(): (string | undefined)[] | undefined;
51
+ /** `SELECT` head with joins - `COUNT(*)` when the query selects nothing. */
52
+ protected select(): (string | string[] | undefined)[];
53
+ /** `FROM` clause of the main table. */
54
+ protected from(): string[] | undefined;
55
+ /** A parameter placeholder. */
24
56
  protected param(_from: Parameter): string;
57
+ /** One condition. `null` renders `IS` / `IS NOT`; an empty list a constant. */
25
58
  protected filter(left: Field, op: string, right: unknown): string;
59
+ /** `WHERE` clause - top level joined with AND, alternating with OR by depth. */
26
60
  protected where(): string[] | undefined;
61
+ /** `ORDER BY` clause. */
27
62
  protected order(): string | undefined;
63
+ /** `LIMIT` and `OFFSET` clauses. */
28
64
  protected limit(): (string | 0 | undefined)[];
29
65
  }
30
66
  //#endregion