@minnowdb/core 0.2.1 → 0.4.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.
Files changed (270) hide show
  1. package/README.md +23 -32
  2. package/dist/block-format/block.d.ts +32 -13
  3. package/dist/block-format/block.js +179 -55
  4. package/dist/block-format/checksum.d.ts +2 -1
  5. package/dist/block-format/checksum.js +5 -2
  6. package/dist/block-format/codecs.d.ts +7 -2
  7. package/dist/block-format/codecs.js +53 -12
  8. package/dist/block-format/column.d.ts +3 -2
  9. package/dist/block-format/column.js +96 -30
  10. package/dist/block-format/index.d.ts +2 -2
  11. package/dist/block-format/index.js +2 -2
  12. package/dist/block-format/physical.d.ts +8 -2
  13. package/dist/block-format/physical.js +14 -6
  14. package/dist/block-format/types.d.ts +7 -3
  15. package/dist/block-format/types.js +0 -1
  16. package/dist/block-format/unicode.d.ts +11 -0
  17. package/dist/block-format/unicode.js +46 -0
  18. package/dist/date-value.d.ts +15 -0
  19. package/dist/date-value.js +64 -0
  20. package/dist/engine/artifact-cache.d.ts +2 -1
  21. package/dist/engine/artifact-cache.js +5 -1
  22. package/dist/engine/batch.d.ts +11 -3
  23. package/dist/engine/batch.js +17 -7
  24. package/dist/engine/buffered-writer.d.ts +2 -1
  25. package/dist/engine/buffered-writer.js +34 -9
  26. package/dist/engine/cache-limits.d.ts +25 -0
  27. package/dist/engine/cache-limits.js +25 -0
  28. package/dist/engine/catalog.d.ts +24 -5
  29. package/dist/engine/catalog.js +34 -7
  30. package/dist/engine/client.d.ts +29 -7
  31. package/dist/engine/client.js +216 -40
  32. package/dist/engine/database.d.ts +224 -39
  33. package/dist/engine/database.js +7475 -1539
  34. package/dist/engine/defaults.d.ts +4 -8
  35. package/dist/engine/defaults.js +46 -22
  36. package/dist/engine/errors.d.ts +19 -1
  37. package/dist/engine/errors.js +32 -2
  38. package/dist/engine/fts.d.ts +0 -6
  39. package/dist/engine/fts.js +41 -14
  40. package/dist/engine/group-index.d.ts +0 -1
  41. package/dist/engine/group-index.js +6 -11
  42. package/dist/engine/index.d.ts +16 -10
  43. package/dist/engine/index.js +12 -9
  44. package/dist/engine/join-index.d.ts +0 -1
  45. package/dist/engine/join-index.js +2 -2
  46. package/dist/engine/keyed-live.d.ts +57 -0
  47. package/dist/engine/keyed-live.js +226 -0
  48. package/dist/engine/live-api.d.ts +4 -0
  49. package/dist/engine/live-api.js +4 -0
  50. package/dist/engine/live.d.ts +43 -26
  51. package/dist/engine/live.js +504 -126
  52. package/dist/engine/memory.d.ts +2 -1
  53. package/dist/engine/memory.js +3 -2
  54. package/dist/engine/optimizer.d.ts +0 -1
  55. package/dist/engine/optimizer.js +262 -27
  56. package/dist/engine/query-api.d.ts +3 -0
  57. package/dist/engine/query-api.js +3 -0
  58. package/dist/engine/query-cache.d.ts +1 -2
  59. package/dist/engine/query-cache.js +7 -5
  60. package/dist/engine/query.d.ts +134 -29
  61. package/dist/engine/query.js +1668 -372
  62. package/dist/engine/result-wire.d.ts +0 -1
  63. package/dist/engine/result-wire.js +2 -2
  64. package/dist/engine/schema-wire.d.ts +6 -3
  65. package/dist/engine/schema-wire.js +40 -34
  66. package/dist/engine/schema.d.ts +156 -80
  67. package/dist/engine/schema.js +570 -108
  68. package/dist/engine/sort-keys.d.ts +4 -4
  69. package/dist/engine/sort-keys.js +44 -29
  70. package/dist/engine/sql-domains.d.ts +31 -0
  71. package/dist/engine/sql-domains.js +585 -0
  72. package/dist/engine/sql-driver.d.ts +19 -0
  73. package/dist/engine/sql-driver.js +1 -0
  74. package/dist/engine/sql-json.d.ts +7 -9
  75. package/dist/engine/sql-json.js +75 -15
  76. package/dist/engine/sql-semantics.d.ts +8 -3
  77. package/dist/engine/sql-semantics.js +458 -30
  78. package/dist/engine/typed-live.d.ts +67 -0
  79. package/dist/engine/typed-live.js +349 -0
  80. package/dist/engine/vector.d.ts +12 -2
  81. package/dist/engine/vector.js +635 -119
  82. package/dist/engine/worker-host.d.ts +9 -2
  83. package/dist/engine/worker-host.js +620 -152
  84. package/dist/engine/worker.d.ts +0 -1
  85. package/dist/engine/worker.js +3 -3
  86. package/dist/engine/write-block-planner.d.ts +18 -0
  87. package/dist/engine/write-block-planner.js +112 -0
  88. package/dist/index.d.ts +0 -1
  89. package/dist/index.js +0 -1
  90. package/dist/plan/index.d.ts +3 -4
  91. package/dist/plan/index.js +3 -4
  92. package/dist/storage/index.d.ts +1 -1
  93. package/dist/storage/index.js +1 -1
  94. package/dist/storage/indexeddb.d.ts +99 -51
  95. package/dist/storage/indexeddb.js +13448 -2660
  96. package/dist/storage/memory.d.ts +64 -57
  97. package/dist/storage/memory.js +1042 -128
  98. package/dist/storage/opfs/files.d.ts +18 -7
  99. package/dist/storage/opfs/files.js +115 -28
  100. package/dist/storage/opfs/index.d.ts +1 -1
  101. package/dist/storage/opfs/index.js +1 -1
  102. package/dist/storage/opfs/leader.d.ts +409 -75
  103. package/dist/storage/opfs/leader.js +4621 -650
  104. package/dist/storage/opfs/rpc.d.ts +15 -3
  105. package/dist/storage/opfs/rpc.js +224 -2
  106. package/dist/storage/opfs/snapshot-ledger.d.ts +40 -0
  107. package/dist/storage/opfs/snapshot-ledger.js +281 -0
  108. package/dist/storage/opfs/store.d.ts +33 -99
  109. package/dist/storage/opfs/store.js +453 -364
  110. package/dist/storage/persistence.d.ts +37 -0
  111. package/dist/storage/persistence.js +78 -0
  112. package/dist/storage/snapshot-stream.d.ts +24 -0
  113. package/dist/storage/snapshot-stream.js +897 -0
  114. package/dist/storage/snapshot.d.ts +9 -85
  115. package/dist/storage/snapshot.js +33 -265
  116. package/dist/storage/toolkit/extents.d.ts +41 -7
  117. package/dist/storage/toolkit/extents.js +402 -39
  118. package/dist/storage/toolkit/index.d.ts +4 -5
  119. package/dist/storage/toolkit/index.js +28 -4
  120. package/dist/storage/toolkit/record-core.d.ts +182 -55
  121. package/dist/storage/toolkit/record-core.js +6158 -1331
  122. package/dist/storage/toolkit/sync-file.d.ts +10 -1
  123. package/dist/storage/toolkit/sync-file.js +50 -2
  124. package/dist/storage/toolkit/wal.d.ts +23 -5
  125. package/dist/storage/toolkit/wal.js +89 -27
  126. package/dist/storage/toolkit/wire.d.ts +15 -2
  127. package/dist/storage/toolkit/wire.js +199 -10
  128. package/dist/storage/types.d.ts +1439 -204
  129. package/dist/storage/types.js +1745 -141
  130. package/dist/testing/block-store-conformance.d.ts +0 -1
  131. package/dist/testing/block-store-conformance.js +1009 -119
  132. package/dist/testing/index.d.ts +46 -26
  133. package/dist/testing/index.js +112 -57
  134. package/dist/testing/opfs-shim.d.ts +13 -3
  135. package/dist/testing/opfs-shim.js +40 -6
  136. package/dist/testing/simulator.d.ts +97 -0
  137. package/dist/testing/simulator.js +591 -0
  138. package/dist/testing/sqllogictest.d.ts +89 -0
  139. package/dist/testing/sqllogictest.js +434 -0
  140. package/dist/transactions/index.d.ts +92 -16
  141. package/dist/transactions/index.js +1074 -236
  142. package/dist/worker-protocol/index.d.ts +3 -2
  143. package/dist/worker-protocol/index.js +2 -5
  144. package/package.json +53 -3
  145. package/postgres-feature-profile.json +223 -0
  146. package/sql-feature-matrix.json +172 -252
  147. package/dist/block-format/block.d.ts.map +0 -1
  148. package/dist/block-format/block.js.map +0 -1
  149. package/dist/block-format/checksum.d.ts.map +0 -1
  150. package/dist/block-format/checksum.js.map +0 -1
  151. package/dist/block-format/codecs.d.ts.map +0 -1
  152. package/dist/block-format/codecs.js.map +0 -1
  153. package/dist/block-format/column.d.ts.map +0 -1
  154. package/dist/block-format/column.js.map +0 -1
  155. package/dist/block-format/index.d.ts.map +0 -1
  156. package/dist/block-format/index.js.map +0 -1
  157. package/dist/block-format/physical.d.ts.map +0 -1
  158. package/dist/block-format/physical.js.map +0 -1
  159. package/dist/block-format/types.d.ts.map +0 -1
  160. package/dist/block-format/types.js.map +0 -1
  161. package/dist/engine/artifact-cache.d.ts.map +0 -1
  162. package/dist/engine/artifact-cache.js.map +0 -1
  163. package/dist/engine/batch.d.ts.map +0 -1
  164. package/dist/engine/batch.js.map +0 -1
  165. package/dist/engine/buffered-writer.d.ts.map +0 -1
  166. package/dist/engine/buffered-writer.js.map +0 -1
  167. package/dist/engine/catalog.d.ts.map +0 -1
  168. package/dist/engine/catalog.js.map +0 -1
  169. package/dist/engine/client.d.ts.map +0 -1
  170. package/dist/engine/client.js.map +0 -1
  171. package/dist/engine/coordinator.d.ts +0 -17
  172. package/dist/engine/coordinator.d.ts.map +0 -1
  173. package/dist/engine/coordinator.js +0 -60
  174. package/dist/engine/coordinator.js.map +0 -1
  175. package/dist/engine/database.d.ts.map +0 -1
  176. package/dist/engine/database.js.map +0 -1
  177. package/dist/engine/defaults.d.ts.map +0 -1
  178. package/dist/engine/defaults.js.map +0 -1
  179. package/dist/engine/errors.d.ts.map +0 -1
  180. package/dist/engine/errors.js.map +0 -1
  181. package/dist/engine/fts.d.ts.map +0 -1
  182. package/dist/engine/fts.js.map +0 -1
  183. package/dist/engine/group-index.d.ts.map +0 -1
  184. package/dist/engine/group-index.js.map +0 -1
  185. package/dist/engine/index.d.ts.map +0 -1
  186. package/dist/engine/index.js.map +0 -1
  187. package/dist/engine/join-index.d.ts.map +0 -1
  188. package/dist/engine/join-index.js.map +0 -1
  189. package/dist/engine/live.d.ts.map +0 -1
  190. package/dist/engine/live.js.map +0 -1
  191. package/dist/engine/memory.d.ts.map +0 -1
  192. package/dist/engine/memory.js.map +0 -1
  193. package/dist/engine/optimizer.d.ts.map +0 -1
  194. package/dist/engine/optimizer.js.map +0 -1
  195. package/dist/engine/query-cache.d.ts.map +0 -1
  196. package/dist/engine/query-cache.js.map +0 -1
  197. package/dist/engine/query.d.ts.map +0 -1
  198. package/dist/engine/query.js.map +0 -1
  199. package/dist/engine/result-wire.d.ts.map +0 -1
  200. package/dist/engine/result-wire.js.map +0 -1
  201. package/dist/engine/schema-wire.d.ts.map +0 -1
  202. package/dist/engine/schema-wire.js.map +0 -1
  203. package/dist/engine/schema.d.ts.map +0 -1
  204. package/dist/engine/schema.js.map +0 -1
  205. package/dist/engine/sort-keys.d.ts.map +0 -1
  206. package/dist/engine/sort-keys.js.map +0 -1
  207. package/dist/engine/sql-json.d.ts.map +0 -1
  208. package/dist/engine/sql-json.js.map +0 -1
  209. package/dist/engine/sql-semantics.d.ts.map +0 -1
  210. package/dist/engine/sql-semantics.js.map +0 -1
  211. package/dist/engine/vector.d.ts.map +0 -1
  212. package/dist/engine/vector.js.map +0 -1
  213. package/dist/engine/worker-host.d.ts.map +0 -1
  214. package/dist/engine/worker-host.js.map +0 -1
  215. package/dist/engine/worker.d.ts.map +0 -1
  216. package/dist/engine/worker.js.map +0 -1
  217. package/dist/index.d.ts.map +0 -1
  218. package/dist/index.js.map +0 -1
  219. package/dist/plan/index.d.ts.map +0 -1
  220. package/dist/plan/index.js.map +0 -1
  221. package/dist/storage/fixture-shape.d.ts +0 -42
  222. package/dist/storage/fixture-shape.d.ts.map +0 -1
  223. package/dist/storage/fixture-shape.js +0 -146
  224. package/dist/storage/fixture-shape.js.map +0 -1
  225. package/dist/storage/index.d.ts.map +0 -1
  226. package/dist/storage/index.js.map +0 -1
  227. package/dist/storage/indexeddb.d.ts.map +0 -1
  228. package/dist/storage/indexeddb.js.map +0 -1
  229. package/dist/storage/memory.d.ts.map +0 -1
  230. package/dist/storage/memory.js.map +0 -1
  231. package/dist/storage/opfs/files.d.ts.map +0 -1
  232. package/dist/storage/opfs/files.js.map +0 -1
  233. package/dist/storage/opfs/index.d.ts.map +0 -1
  234. package/dist/storage/opfs/index.js.map +0 -1
  235. package/dist/storage/opfs/leader.d.ts.map +0 -1
  236. package/dist/storage/opfs/leader.js.map +0 -1
  237. package/dist/storage/opfs/rpc.d.ts.map +0 -1
  238. package/dist/storage/opfs/rpc.js.map +0 -1
  239. package/dist/storage/opfs/store.d.ts.map +0 -1
  240. package/dist/storage/opfs/store.js.map +0 -1
  241. package/dist/storage/snapshot.d.ts.map +0 -1
  242. package/dist/storage/snapshot.js.map +0 -1
  243. package/dist/storage/toolkit/extents.d.ts.map +0 -1
  244. package/dist/storage/toolkit/extents.js.map +0 -1
  245. package/dist/storage/toolkit/index.d.ts.map +0 -1
  246. package/dist/storage/toolkit/index.js.map +0 -1
  247. package/dist/storage/toolkit/record-core.d.ts.map +0 -1
  248. package/dist/storage/toolkit/record-core.js.map +0 -1
  249. package/dist/storage/toolkit/sync-file.d.ts.map +0 -1
  250. package/dist/storage/toolkit/sync-file.js.map +0 -1
  251. package/dist/storage/toolkit/wal.d.ts.map +0 -1
  252. package/dist/storage/toolkit/wal.js.map +0 -1
  253. package/dist/storage/toolkit/wire.d.ts.map +0 -1
  254. package/dist/storage/toolkit/wire.js.map +0 -1
  255. package/dist/storage/types.d.ts.map +0 -1
  256. package/dist/storage/types.js.map +0 -1
  257. package/dist/testing/block-store-conformance.d.ts.map +0 -1
  258. package/dist/testing/block-store-conformance.js.map +0 -1
  259. package/dist/testing/index.d.ts.map +0 -1
  260. package/dist/testing/index.js.map +0 -1
  261. package/dist/testing/opfs-shim.d.ts.map +0 -1
  262. package/dist/testing/opfs-shim.js.map +0 -1
  263. package/dist/testing/seeds.d.ts +0 -11
  264. package/dist/testing/seeds.d.ts.map +0 -1
  265. package/dist/testing/seeds.js +0 -50
  266. package/dist/testing/seeds.js.map +0 -1
  267. package/dist/transactions/index.d.ts.map +0 -1
  268. package/dist/transactions/index.js.map +0 -1
  269. package/dist/worker-protocol/index.d.ts.map +0 -1
  270. package/dist/worker-protocol/index.js.map +0 -1
@@ -65,4 +65,3 @@ export declare function encodeQueryResult(result: QueryResult): EncodedQueryResu
65
65
  export declare function encodeQueryRows(rows: readonly QueryRow[]): EncodedQueryResult;
66
66
  export declare function decodeQueryResult(payload: unknown): QueryResult;
67
67
  export declare function isWireQueryResult(value: unknown): value is WireQueryResult;
68
- //# sourceMappingURL=result-wire.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { dateMilliseconds } from "../date-value.js";
1
2
  export function encodeQueryResult(result) {
2
3
  return encodeRows(result.columns, result.rows);
3
4
  }
@@ -115,7 +116,7 @@ function encodeColumn(name, rows) {
115
116
  nulls[index] = 1;
116
117
  }
117
118
  else if (value instanceof Date) {
118
- values[index] = value.getTime();
119
+ values[index] = dateMilliseconds(value);
119
120
  }
120
121
  else {
121
122
  return encodeMixed(name, rows);
@@ -261,4 +262,3 @@ function decodeColumnValues(column, rowCount) {
261
262
  }
262
263
  return values;
263
264
  }
264
- //# sourceMappingURL=result-wire.js.map
@@ -1,5 +1,5 @@
1
- import type { ColumnDefault } from "../storage/index.js";
2
- import { type AnyTable, type MigrationStep, type ReferentialAction, type SchemaColumnType, type SchemaDefinition, type TableCheck } from "./schema.js";
1
+ import type { ColumnDefault, SqlDomain } from "../storage/types.js";
2
+ import { type AnyTable, type MigrationStep, type ReferentialAction, type SchemaColumnType, type SchemaDefinition, type TableCheck, type TableForeignKey } from "./schema.js";
3
3
  /**
4
4
  * Structured-clone-safe mirror of the schema DSL. Column builders and table validators carry
5
5
  * methods, so a schema cannot cross a postMessage boundary as-is; these types keep only the data
@@ -9,6 +9,8 @@ export interface WireColumn {
9
9
  readonly type: SchemaColumnType;
10
10
  readonly isNullable: boolean;
11
11
  readonly isUnique: boolean;
12
+ readonly integer?: true;
13
+ readonly sqlDomain?: SqlDomain;
12
14
  readonly defaultSpec?: ColumnDefault;
13
15
  readonly renamedFromName?: string;
14
16
  readonly reference?: {
@@ -23,6 +25,8 @@ export interface WireColumn {
23
25
  export interface WireTable {
24
26
  readonly name: string;
25
27
  readonly columns: Record<string, WireColumn>;
28
+ readonly primaryKey?: readonly string[];
29
+ readonly foreignKeys?: readonly TableForeignKey[];
26
30
  /** Absent rather than empty so a frame written without the field stays readable. */
27
31
  readonly checks?: readonly TableCheck[];
28
32
  }
@@ -89,4 +93,3 @@ export type WireMigrationStep = {
89
93
  export declare function serializeSchema(definition: SchemaDefinition<readonly AnyTable[]>): WireSchema;
90
94
  export declare function serializeMigrationSteps(steps: readonly MigrationStep[]): WireMigrationStep[];
91
95
  export declare function deserializeSchema(wire: WireSchema): SchemaDefinition<readonly AnyTable[]>;
92
- //# sourceMappingURL=schema-wire.d.ts.map
@@ -1,22 +1,25 @@
1
- import { column, columnWithDefaultSpec, schema, table, view, } from "./schema.js";
2
- function serializeColumn(definition) {
1
+ import { columnFromState, schema, table, view, } from "./schema.js";
2
+ function serializeColumn(definition, frozen) {
3
+ const backfillValue = frozen === undefined
4
+ ? typeof definition.backfillValue === "function"
5
+ ? definition.backfillValue()
6
+ : definition.backfillValue
7
+ : frozen.backfillValue;
3
8
  return {
4
9
  type: definition.type,
5
10
  isNullable: definition.isNullable,
6
11
  isUnique: definition.isUnique,
12
+ ...(definition.integer ? { integer: true } : {}),
13
+ ...(definition.sqlDomain === undefined
14
+ ? {}
15
+ : { sqlDomain: structuredClone(definition.sqlDomain) }),
7
16
  ...(definition.defaultSpec === undefined ? {} : { defaultSpec: { ...definition.defaultSpec } }),
8
17
  ...(definition.renamedFromName === undefined
9
18
  ? {}
10
19
  : { renamedFromName: definition.renamedFromName }),
11
20
  ...(definition.reference === undefined ? {} : { reference: { ...definition.reference } }),
12
21
  ...(definition.enumValues === undefined ? {} : { enumValues: [...definition.enumValues] }),
13
- ...(definition.backfillValue === undefined
14
- ? {}
15
- : {
16
- backfillValue: typeof definition.backfillValue === "function"
17
- ? definition.backfillValue()
18
- : definition.backfillValue,
19
- }),
22
+ ...(backfillValue === undefined ? {} : { backfillValue }),
20
23
  };
21
24
  }
22
25
  function serializeTable(definition) {
@@ -26,6 +29,10 @@ function serializeTable(definition) {
26
29
  name,
27
30
  serializeColumn(columnDefinition),
28
31
  ])),
32
+ ...(definition.primaryKey.length === 0 ? {} : { primaryKey: [...definition.primaryKey] }),
33
+ ...(definition.foreignKeys.length === 0
34
+ ? {}
35
+ : { foreignKeys: structuredClone(definition.foreignKeys) }),
29
36
  ...(definition.checks.length === 0
30
37
  ? {}
31
38
  : { checks: definition.checks.map((check) => ({ ...check })) }),
@@ -66,7 +73,7 @@ export function serializeMigrationSteps(steps) {
66
73
  kind: "add-column",
67
74
  tableName: step.tableName,
68
75
  columnName: step.columnName,
69
- definition: serializeColumn(step.definition),
76
+ definition: serializeColumn(step.definition, step.backfill === undefined ? {} : { backfillValue: step.backfill }),
70
77
  };
71
78
  case "replace-view":
72
79
  return { kind: "replace-view", view: serializeView(step.view) };
@@ -79,37 +86,36 @@ function deserializeColumn(wire) {
79
86
  if (wire.enumValues !== undefined && wire.type !== "string") {
80
87
  throw new TypeError(`Enum values require a string column, got ${wire.type}`);
81
88
  }
82
- let builder = wire.enumValues === undefined
83
- ? column[wire.type]()
84
- : column.enum(wire.enumValues);
85
- if (wire.isNullable)
86
- builder = builder.nullable();
87
- if (wire.isUnique)
88
- builder = builder.unique();
89
- if (wire.renamedFromName !== undefined)
90
- builder = builder.renamedFrom(wire.renamedFromName);
91
- if (wire.backfillValue !== undefined)
92
- builder = builder.backfill(wire.backfillValue);
93
- if (wire.reference !== undefined) {
94
- builder = builder.references(wire.reference.table, wire.reference.column, {
95
- onDelete: wire.reference.onDelete,
96
- });
97
- }
98
- // Rebuilt from the spec directly rather than through .default(), which would re-interpret the
99
- // reserved generator names.
100
- if (wire.defaultSpec !== undefined)
101
- builder = columnWithDefaultSpec(builder, wire.defaultSpec);
102
- return builder;
89
+ // Rebuild in one step. Chaining dynamic nullable/unique builders is needlessly invariant and
90
+ // used to discard a backfill when a default spec was applied last.
91
+ return columnFromState({
92
+ type: wire.type,
93
+ isNullable: wire.isNullable,
94
+ isUnique: wire.isUnique,
95
+ integer: wire.integer === true,
96
+ ...(wire.sqlDomain === undefined ? {} : { sqlDomain: structuredClone(wire.sqlDomain) }),
97
+ ...(wire.defaultSpec === undefined ? {} : { defaultSpec: wire.defaultSpec }),
98
+ ...(wire.renamedFromName === undefined ? {} : { renamedFromName: wire.renamedFromName }),
99
+ ...(wire.reference === undefined ? {} : { reference: wire.reference }),
100
+ ...(wire.enumValues === undefined ? {} : { enumValues: wire.enumValues }),
101
+ ...(wire.backfillValue === undefined ? {} : { backfillValue: wire.backfillValue }),
102
+ });
103
103
  }
104
104
  function deserializeTable(wire) {
105
- return table(wire.name, Object.fromEntries(Object.entries(wire.columns).map(([name, columnDefinition]) => [
105
+ const columns = Object.fromEntries(Object.entries(wire.columns).map(([name, columnDefinition]) => [
106
106
  name,
107
107
  deserializeColumn(columnDefinition),
108
- ])), wire.checks === undefined ? {} : { checks: wire.checks.map((check) => ({ ...check })) });
108
+ ]));
109
+ const options = {
110
+ ...(wire.foreignKeys === undefined ? {} : { foreignKeys: structuredClone(wire.foreignKeys) }),
111
+ ...(wire.checks === undefined ? {} : { checks: wire.checks.map((check) => ({ ...check })) }),
112
+ };
113
+ return wire.primaryKey === undefined
114
+ ? table(wire.name, columns, options)
115
+ : table(wire.name, columns, { ...options, primaryKey: [...wire.primaryKey] });
109
116
  }
110
117
  export function deserializeSchema(wire) {
111
118
  return schema(wire.tables.map(deserializeTable), {
112
119
  views: (wire.views ?? []).map(deserializeView),
113
120
  });
114
121
  }
115
- //# sourceMappingURL=schema-wire.js.map
@@ -1,6 +1,6 @@
1
- import { type ColumnDefault, type TableColumnRecord, type TableRecord } from "../storage/index.js";
2
- import { type Catalog } from "./catalog.js";
3
- import { type BatchRow } from "./batch.js";
1
+ import { type ColumnDefault, type SqlDomain, type TableColumnRecord, type TableRecord } from "../storage/types.js";
2
+ import { type Catalog, type CatalogColumn, type CatalogTable } from "./catalog.js";
3
+ import { type QueryValue } from "./query.js";
4
4
  /**
5
5
  * Typed schema DSL and catalog migration planning. Column builders carry compile-time value and
6
6
  * nullability types; `planMigration` diffs a schema against the live catalog into metadata-only
@@ -22,6 +22,16 @@ export interface TableCheck {
22
22
  readonly name: string;
23
23
  readonly sql: string;
24
24
  }
25
+ /** A table-level relation, used when either side has a composite primary key. */
26
+ export interface TableForeignKey<TColumnName extends string = string> {
27
+ readonly name: string;
28
+ readonly columns: readonly TColumnName[];
29
+ readonly references: {
30
+ readonly table: string;
31
+ readonly columns: readonly string[];
32
+ };
33
+ readonly onDelete?: ReferentialAction;
34
+ }
25
35
  /**
26
36
  * The constraint name `migrate()` gives a declared relation. It matches the name the SQL parser
27
37
  * derives for an unnamed inline REFERENCES, so a table built either way has the same catalog.
@@ -34,43 +44,34 @@ export declare function foreignKeyName(tableName: string, columnName: string): s
34
44
  export type HasDefault<TValue> = TValue & {
35
45
  readonly __minnowHasDefault?: true;
36
46
  };
37
- /**
38
- * The public name for the flavor, for hand-declared `DB` interfaces (the Kysely convention).
39
- * `InferDatabase` applies it automatically from the schema; write it yourself only when you
40
- * declare the row types by hand and want generated columns to stay omissible on insert:
41
- *
42
- * ```ts
43
- * interface DB {
44
- * notes: { id: Generated<number>; slug: Generated<string>; body: string };
45
- * }
46
- * ```
47
- */
48
- export type Generated<TValue> = HasDefault<TValue>;
49
- export interface ColumnBuilder<TValue, TNullable extends boolean, TUnique extends boolean = false, THasDefault extends boolean = false> {
47
+ export interface ColumnBuilder<TValue extends SchemaValue, TNullable extends boolean, TUnique extends boolean = false, THasDefault extends boolean = false, TInput extends SchemaValue = TValue> {
50
48
  readonly kind: "column";
51
49
  readonly type: SchemaColumnType;
52
50
  readonly isNullable: TNullable;
53
51
  readonly isUnique: TUnique;
54
52
  readonly hasDefault: THasDefault;
53
+ /** Type-only metadata consumed by adapters; optional so it emits no runtime payload. */
54
+ readonly "~types"?: {
55
+ readonly select: TValue;
56
+ readonly input: TInput;
57
+ };
58
+ /** True for exact SQL integer columns; ordinary number columns use Float64 semantics. */
59
+ readonly integer: boolean;
60
+ /** Logical SQL semantics layered over the stable string storage encoding. */
61
+ readonly sqlDomain?: SqlDomain;
55
62
  readonly defaultSpec?: ColumnDefault;
56
- /**
57
- * A userland default generator. Never persisted and never sent to the engine — the typed
58
- * facade (`insertInto`, `typedTable`) calls it for omitted-or-null slots before the batch
59
- * crosses the boundary, so untyped write paths (raw batches, SQL) do not see it.
60
- */
61
- readonly defaultFn?: () => TValue;
62
63
  /** Present on `column.enum()` builders: the closed set of values writes must draw from. */
63
64
  readonly enumValues?: readonly string[];
64
65
  /** What rows written before this column existed read as; see `.backfill()`. */
65
- readonly backfillValue?: TValue | (() => TValue);
66
+ readonly backfillValue?: TInput | (() => TInput);
66
67
  readonly renamedFromName?: string;
67
68
  readonly reference?: ColumnReferenceSpec;
68
69
  /** Marks the column nullable; inserts may omit it and reads may return null. */
69
- nullable(): ColumnBuilder<TValue, true, TUnique, THasDefault>;
70
+ nullable(): ColumnBuilder<TValue, true, TUnique, THasDefault, TInput>;
70
71
  /** Marks the table's unique key; exactly one non-nullable column may carry it. */
71
- unique(): ColumnBuilder<TValue, TNullable, true, THasDefault>;
72
+ unique(this: ColumnBuilder<TValue, false, TUnique, THasDefault, TInput>): ColumnBuilder<TValue, TNullable, true, THasDefault, TInput>;
72
73
  /** Declares this column as the rename target of an existing catalog column. */
73
- renamedFrom(name: string): ColumnBuilder<TValue, TNullable, TUnique, THasDefault>;
74
+ renamedFrom(name: string): ColumnBuilder<TValue, TNullable, TUnique, THasDefault, TInput>;
74
75
  /**
75
76
  * What rows written before this column existed read as, instead of NULL. Giving one is what
76
77
  * makes adding a non-nullable column possible: no stored byte is rewritten, and reads
@@ -80,7 +81,7 @@ export interface ColumnBuilder<TValue, TNullable extends boolean, TUnique extend
80
81
  * catalog — so it can derive a value (a timestamp, a version stamp) without readers ever
81
82
  * disagreeing. It cannot derive from other columns; that would need a value per row.
82
83
  */
83
- backfill(value: TValue | (() => TValue)): ColumnBuilder<TValue, TNullable, TUnique, THasDefault>;
84
+ backfill(this: ColumnBuilder<TValue, false, TUnique, THasDefault, TInput>, value: TInput | (() => TInput)): ColumnBuilder<TValue, TNullable, TUnique, THasDefault, TInput>;
84
85
  /**
85
86
  * Declares a FOREIGN KEY onto another table's unique key. `migrate()` creates it as a real
86
87
  * constraint, so a write naming a parent row that does not exist is rejected — the same
@@ -88,39 +89,75 @@ export interface ColumnBuilder<TValue, TNullable extends boolean, TUnique extend
88
89
  *
89
90
  * `onDelete` defaults to `"restrict"`. `"set null"` requires a nullable column.
90
91
  */
91
- references(table: string, column: string, options?: {
92
- onDelete?: ReferentialAction;
93
- }): ColumnBuilder<TValue, TNullable, TUnique, THasDefault>;
92
+ references(this: ColumnBuilder<TValue, TNullable, TUnique, THasDefault, TInput>, table: string, column: string, options?: {
93
+ onDelete?: Exclude<ReferentialAction, "set null">;
94
+ }): ColumnBuilder<TValue, TNullable, TUnique, THasDefault, TInput>;
95
+ references(this: ColumnBuilder<TValue, true, TUnique, THasDefault, TInput>, table: string, column: string, options: {
96
+ onDelete: "set null";
97
+ }): ColumnBuilder<TValue, TNullable, TUnique, THasDefault, TInput>;
98
+ /** Declares a literal SQL default. Omission or SQL `DEFAULT` invokes it; NULL does not. */
99
+ default(value: TInput): ColumnBuilder<TValue, TNullable, TUnique, true, TInput>;
94
100
  /**
95
- * Fills null-or-absent slots at insert time. Requires a non-nullable column.
96
- *
97
- * A plain value persists in the catalog and fills inside the engine, so every write path
98
- * gets it — raw batches, SQL statements, other tabs. Datetime columns accept only "now",
99
- * which stamps one consistent timestamp per batch.
100
- *
101
- * A function is a userland generator (`() => ulid()`): the typed facade calls it just
102
- * before the batch is sent, so it never persists and never crosses the worker boundary —
103
- * and write paths that don't go through the facade don't see it.
101
+ * Declares a variable-free SQL default expression, such as `CURRENT_TIMESTAMP`,
102
+ * `gen_random_uuid()`, or `nextval('orders_id_seq')`. The engine parses and type-checks it
103
+ * before migration and evaluates it once per omitted row.
104
104
  */
105
- default(value: (TValue extends Date ? "now" : TValue) | (() => TValue)): ColumnBuilder<TValue, TNullable, TUnique, true>;
105
+ defaultSql(sql: string): ColumnBuilder<TValue, TNullable, TUnique, true, TInput>;
106
106
  /**
107
- * Generates monotonically increasing integers for null-or-absent slots from a persistent
107
+ * Generates monotonically increasing integers for omitted or SQL `DEFAULT` slots from a persistent
108
108
  * per-table counter that is atomic across tabs. Explicit values are allowed and bump the
109
109
  * counter past their maximum. Number unique-key columns only.
110
110
  */
111
- autoIncrement: TValue extends number ? () => ColumnBuilder<TValue, TNullable, TUnique, true> : never;
111
+ autoIncrement: TValue extends number ? (this: ColumnBuilder<TValue, false, true, THasDefault, TInput>) => ColumnBuilder<TValue, TNullable, TUnique, true, TInput> : never;
112
+ }
113
+ type SchemaValue = boolean | number | string | Date;
114
+ /**
115
+ * Metadata shared by every concrete ColumnBuilder. Schema collections need an existential
116
+ * column type: including fluent methods here would make TValue invariant because those methods
117
+ * both consume and return it. Public inference still retains each concrete builder in TColumns.
118
+ */
119
+ interface AnyColumn {
120
+ readonly kind: "column";
121
+ readonly type: SchemaColumnType;
122
+ readonly isNullable: boolean;
123
+ readonly isUnique: boolean;
124
+ readonly hasDefault: boolean;
125
+ readonly integer: boolean;
126
+ readonly sqlDomain?: SqlDomain;
127
+ readonly defaultSpec?: ColumnDefault;
128
+ readonly enumValues?: readonly string[];
129
+ readonly backfillValue?: SchemaValue | (() => SchemaValue);
130
+ readonly renamedFromName?: string;
131
+ readonly reference?: ColumnReferenceSpec;
112
132
  }
113
- type AnyColumn = ColumnBuilder<boolean | number | string | Date, boolean, boolean, boolean>;
114
133
  /**
115
134
  * Rebuilds a column carrying an exact default spec — the wire layer's escape hatch, since the
116
- * public `.default()` interprets "now" on datetime columns and cannot express auto-increment.
135
+ * public `.default()` accepts literals and cannot express auto-increment catalog metadata.
117
136
  */
118
- export declare function columnWithDefaultSpec(base: Pick<AnyColumn, "type" | "isNullable" | "isUnique" | "renamedFromName" | "reference" | "enumValues">, spec: ColumnDefault): AnyColumn;
137
+ export declare function columnWithDefaultSpec(base: Pick<AnyColumn, "type" | "isNullable" | "isUnique" | "renamedFromName" | "reference" | "enumValues"> & Partial<Pick<AnyColumn, "integer" | "sqlDomain">>, spec: ColumnDefault): AnyColumn;
138
+ /** Rebuilds a fluent column from structured-clone-safe metadata. */
139
+ export declare function columnFromState(state: Pick<AnyColumn, "type" | "isNullable" | "isUnique"> & Partial<Pick<AnyColumn, "integer" | "sqlDomain" | "renamedFromName" | "reference" | "defaultSpec" | "enumValues" | "backfillValue">>): AnyColumn;
119
140
  export declare const column: {
120
- boolean: () => ColumnBuilder<boolean, false, false, false>;
121
- number: () => ColumnBuilder<number, false, false, false>;
122
- string: () => ColumnBuilder<string, false, false, false>;
123
- datetime: () => ColumnBuilder<Date, false, false, false>;
141
+ boolean: () => ColumnBuilder<boolean, false, false, false, boolean>;
142
+ number: () => ColumnBuilder<number, false, false, false, number>;
143
+ /** Exact safe-integer semantics, matching SQL INTEGER/SMALLINT/BIGINT. */
144
+ integer: () => ColumnBuilder<number, false, false, false, number>;
145
+ string: () => ColumnBuilder<string, false, false, false, string>;
146
+ datetime: () => ColumnBuilder<Date, false, false, false, Date>;
147
+ /** Exact decimal SQL NUMERIC. Selects return strings; writes accept strings or numbers. */
148
+ numeric: (options?: {
149
+ precision?: number;
150
+ scale?: number;
151
+ }) => ColumnBuilder<string, false, false, false, string | number>;
152
+ json: () => ColumnBuilder<string, false, false, false, string>;
153
+ jsonb: () => ColumnBuilder<string, false, false, false, string>;
154
+ uuid: () => ColumnBuilder<string, false, false, false, string>;
155
+ time: () => ColumnBuilder<string, false, false, false, string>;
156
+ interval: () => ColumnBuilder<string, false, false, false, string>;
157
+ /** JSON array text at the JavaScript boundary, with the SQL element type retained in metadata. */
158
+ array: (element: string) => ColumnBuilder<string, false, false, false, string>;
159
+ /** A named SQL enum domain, distinct from the lightweight `column.enum()` restriction. */
160
+ sqlEnum: <const TValues extends readonly [string, ...string[]]>(name: string, values: TValues) => ColumnBuilder<TValues[number], false>;
124
161
  /**
125
162
  * A string column restricted to a closed set of values, typed as their literal union:
126
163
  *
@@ -135,11 +172,13 @@ export declare const column: {
135
172
  */
136
173
  enum: <const TValues extends readonly [string, ...string[]]>(values: TValues) => ColumnBuilder<TValues[number], false>;
137
174
  };
138
- export interface TableSchema<TColumns extends Record<string, AnyColumn>, TName extends string = string> {
175
+ /** Runtime table shape accepted by schema collections without erasing concrete table inference. */
176
+ export interface AnyTable {
139
177
  readonly kind: "table";
140
- readonly name: TName;
141
- readonly columns: TColumns;
142
- /** Row conditions every write must satisfy; empty when none were declared. */
178
+ readonly name: string;
179
+ readonly columns: Record<string, AnyColumn>;
180
+ readonly primaryKey: readonly string[];
181
+ readonly foreignKeys: readonly TableForeignKey[];
143
182
  readonly checks: readonly TableCheck[];
144
183
  /** Standard Schema-compatible runtime validator for one insert row. */
145
184
  readonly "~standard": {
@@ -155,8 +194,21 @@ export interface TableSchema<TColumns extends Record<string, AnyColumn>, TName e
155
194
  };
156
195
  };
157
196
  }
158
- export type AnyTable = TableSchema<Record<string, AnyColumn>>;
159
- export interface TableOptions {
197
+ export interface TableSchema<TColumns extends Record<string, AnyColumn>, TName extends string = string, TPrimaryKey extends ReadonlyArray<keyof TColumns & string> = readonly []> extends AnyTable {
198
+ readonly name: TName;
199
+ readonly columns: TColumns;
200
+ /** Ordered table-level primary key. Empty when `.unique()` owns the scalar identity. */
201
+ readonly primaryKey: TPrimaryKey;
202
+ /** Table-level relations, including composite FOREIGN KEY declarations. */
203
+ readonly foreignKeys: ReadonlyArray<TableForeignKey<keyof TColumns & string>>;
204
+ /** Row conditions every write must satisfy; empty when none were declared. */
205
+ readonly checks: readonly TableCheck[];
206
+ }
207
+ export interface TableOptions<TColumns extends Record<string, AnyColumn> = Record<string, AnyColumn>, TPrimaryKey extends ReadonlyArray<keyof TColumns & string> = readonly []> {
208
+ /** Ordered PRIMARY KEY columns. Use `.unique()` for the existing scalar shorthand. */
209
+ readonly primaryKey?: TPrimaryKey;
210
+ /** Table-level relations; required for composite FOREIGN KEYs. */
211
+ readonly foreignKeys?: ReadonlyArray<TableForeignKey<keyof TColumns & string>>;
160
212
  /**
161
213
  * Row conditions every write must satisfy (E141-06), each a boolean SQL expression over this
162
214
  * table's own columns — the declarative form of `CONSTRAINT name CHECK (sql)`. The engine
@@ -165,7 +217,12 @@ export interface TableOptions {
165
217
  */
166
218
  readonly checks?: readonly TableCheck[];
167
219
  }
168
- export declare function table<const TName extends string, TColumns extends Record<string, AnyColumn>>(name: TName, columns: TColumns, options?: TableOptions): TableSchema<TColumns, TName>;
220
+ export declare function table<const TName extends string, TColumns extends Record<string, AnyColumn>, const TPrimaryKey extends ReadonlyArray<keyof TColumns & string>>(name: TName, columns: TColumns, options: TableOptions<TColumns, TPrimaryKey> & {
221
+ readonly primaryKey: TPrimaryKey;
222
+ }): TableSchema<TColumns, TName, TPrimaryKey>;
223
+ export declare function table<const TName extends string, TColumns extends Record<string, AnyColumn>>(name: TName, columns: TColumns, options?: Omit<TableOptions<TColumns>, "primaryKey"> & {
224
+ readonly primaryKey?: never;
225
+ }): TableSchema<TColumns, TName>;
169
226
  /**
170
227
  * The FOREIGN KEY constraints a table declares, in column order. This is the single derivation
171
228
  * of "what relations does this table have" — `planMigration` diffs against it and `migrate()`
@@ -173,9 +230,9 @@ export declare function table<const TName extends string, TColumns extends Recor
173
230
  */
174
231
  export declare function declaredForeignKeys(definition: AnyTable): Array<{
175
232
  name: string;
176
- column: string;
233
+ columns: string[];
177
234
  parentTable: string;
178
- parentColumn: string;
235
+ parentColumns: string[];
179
236
  onDelete: ReferentialAction;
180
237
  }>;
181
238
  /**
@@ -217,7 +274,14 @@ export interface SchemaDefinition<TTables extends readonly AnyTable[], TViews ex
217
274
  export declare function schema<TTables extends readonly AnyTable[], TViews extends readonly AnyView[] = []>(tables: TTables, options?: {
218
275
  views?: TViews;
219
276
  }): SchemaDefinition<TTables, TViews>;
220
- type ColumnValue<TColumn> = TColumn extends ColumnBuilder<infer TValue, infer TNullable, boolean, infer THasDefault> ? THasDefault extends true ? HasDefault<TNullable extends true ? TValue | null : TValue> : TNullable extends true ? TValue | null : TValue : never;
277
+ type ColumnTypeMetadata<TColumn> = TColumn extends {
278
+ readonly "~types"?: infer TMetadata extends {
279
+ readonly select: unknown;
280
+ readonly input: unknown;
281
+ };
282
+ } ? NonNullable<TMetadata> : never;
283
+ type ColumnValue<TColumn extends AnyColumn> = TColumn["isNullable"] extends true ? ColumnTypeMetadata<TColumn>["select"] | null : ColumnTypeMetadata<TColumn>["select"];
284
+ type ColumnInputValue<TColumn extends AnyColumn> = TColumn["isNullable"] extends true ? ColumnTypeMetadata<TColumn>["input"] | null : ColumnTypeMetadata<TColumn>["input"];
221
285
  /** The complete row shape a read returns. */
222
286
  export type InferRow<TTable extends AnyTable> = {
223
287
  [K in keyof TTable["columns"]]: ColumnValue<TTable["columns"][K]>;
@@ -237,16 +301,22 @@ type DefaultKeys<TTable extends AnyTable> = {
237
301
  }[keyof TTable["columns"]];
238
302
  type OptionalInsertKeys<TTable extends AnyTable> = NullableKeys<TTable> | DefaultKeys<TTable>;
239
303
  /** Insert rows require every non-nullable column and may omit nullable or default-bearing ones. */
240
- export type InferInsertRow<TTable extends AnyTable> = Omit<InferRow<TTable>, OptionalInsertKeys<TTable>> & {
241
- [K in OptionalInsertKeys<TTable>]?: ColumnValue<TTable["columns"][K]>;
304
+ export type InferInsertRow<TTable extends AnyTable> = Omit<{
305
+ [K in keyof TTable["columns"]]: ColumnInputValue<TTable["columns"][K]>;
306
+ }, OptionalInsertKeys<TTable>> & {
307
+ [K in OptionalInsertKeys<TTable>]?: ColumnInputValue<TTable["columns"][K]>;
242
308
  };
309
+ /** Scalar `.unique()` keys plus columns named by a table-level primary key. */
310
+ export type PrimaryKeyKeys<TTable extends AnyTable> = {
311
+ [K in keyof TTable["columns"]]: TTable["columns"][K]["isUnique"] extends true ? K : never;
312
+ }[keyof TTable["columns"]] | TTable["primaryKey"][number];
243
313
  /**
244
314
  * Update changes may cover any column except the unique key. An explicit `undefined` entry is
245
315
  * allowed and means "leave this column untouched", so a spread-patch built from optional fields
246
316
  * stays assignable under `exactOptionalPropertyTypes`.
247
317
  */
248
318
  export type InferUpdateChanges<TTable extends AnyTable> = {
249
- [K in keyof TTable["columns"] as TTable["columns"][K]["isUnique"] extends true ? never : K]?: ColumnValue<TTable["columns"][K]> | undefined;
319
+ [K in keyof TTable["columns"] as K extends PrimaryKeyKeys<TTable> ? never : K]?: ColumnInputValue<TTable["columns"][K]> | undefined;
250
320
  };
251
321
  export type MigrationStep = {
252
322
  kind: "create-table";
@@ -332,6 +402,12 @@ export interface MigrationPlan {
332
402
  export declare function isDestructiveStep(step: MigrationStep): step is Extract<MigrationStep, {
333
403
  kind: "drop-column" | "drop-table";
334
404
  }>;
405
+ /**
406
+ * A column can stop being projected without rewriting anything, but not while something else in
407
+ * the catalog still points at it. Each of these would leave a constraint or key referring to a
408
+ * column no longer there, so the drop is refused rather than silently invalidating them.
409
+ */
410
+ export declare function assertColumnDroppable(record: CatalogTable, column: CatalogColumn): void;
335
411
  /**
336
412
  * Diffs the live catalog against a schema into metadata-only steps, in a deterministic order.
337
413
  * Anything unprovable fails explicitly: type changes, dropped columns, unique-key changes,
@@ -351,44 +427,44 @@ export interface PlanMigrationOptions {
351
427
  readonly schemaOwnsDatabase?: boolean;
352
428
  }
353
429
  export declare function planMigration(catalog: Catalog, definition: SchemaDefinition<readonly AnyTable[]>, options?: PlanMigrationOptions): MigrationPlan;
354
- type UniqueKeyValue<TTable extends AnyTable> = {
430
+ type ScalarUniqueKeyValue<TTable extends AnyTable> = {
355
431
  [K in keyof TTable["columns"]]: TTable["columns"][K]["isUnique"] extends true ? ColumnValue<TTable["columns"][K]> : never;
356
432
  }[keyof TTable["columns"]];
433
+ type DeclaredPrimaryKeyValue<TTable extends AnyTable> = {
434
+ [K in TTable["primaryKey"][number]]: ColumnValue<TTable["columns"][K]>;
435
+ };
436
+ /** Scalar keys stay scalar; composite keys are objects keyed by their declared column names. */
437
+ export type PrimaryKeyValue<TTable extends AnyTable> = TTable["primaryKey"] extends readonly [] ? ScalarUniqueKeyValue<TTable> : TTable["primaryKey"] extends readonly [infer TOnly extends keyof TTable["columns"]] ? ColumnValue<TTable["columns"][TOnly]> : DeclaredPrimaryKeyValue<TTable>;
357
438
  type ColumnArrays<TShape> = {
358
439
  [K in keyof TShape]: ReadonlyArray<TShape[K]>;
359
440
  };
360
441
  interface TypedTableDatabase {
361
- insertBatch(tableName: string, rows: readonly BatchRow[]): Promise<unknown>;
362
- upsertBatch(tableName: string, rows: readonly BatchRow[]): Promise<unknown>;
363
- updateBatch(tableName: string, input: {
364
- keys: readonly unknown[];
365
- changes: Readonly<Record<string, readonly unknown[]>>;
366
- }): Promise<unknown>;
367
- deleteBatch(tableName: string, input: {
368
- keys: readonly unknown[];
369
- }): Promise<unknown>;
370
- readTable(tableName: string, options?: {
371
- columns?: readonly string[];
372
- }): Promise<Array<Record<string, unknown>>>;
442
+ execute(sql: string, params?: readonly QueryValue[]): Promise<unknown>;
443
+ query(sql: string, options?: {
444
+ params?: readonly QueryValue[];
445
+ }): Promise<{
446
+ rows: Array<Record<string, unknown>>;
447
+ }>;
373
448
  }
374
449
  /**
375
- * A thin, fully typed handle over the existing batch APIs: inserts require every non-nullable
376
- * column, updates exclude the unique key, and reads return the complete inferred row shape.
450
+ * A thin, fully typed SQL handle: inserts require every non-nullable column, updates exclude the
451
+ * unique key, and reads return the complete inferred row shape. Every operation is rendered as
452
+ * parameterized SQL and goes through the parser/planner/executor; this helper has no private
453
+ * batch or table-read semantics that can drift from SQL.
377
454
  */
378
455
  export declare function typedTable<TTable extends AnyTable>(database: TypedTableDatabase, definition: TTable): {
379
456
  definition: TTable;
380
457
  insert(rows: ReadonlyArray<InferInsertRow<TTable>>): Promise<unknown>;
381
458
  upsert(rows: ReadonlyArray<InferInsertRow<TTable>>): Promise<unknown>;
382
459
  update(input: {
383
- keys: ReadonlyArray<UniqueKeyValue<TTable>>;
460
+ keys: ReadonlyArray<PrimaryKeyValue<TTable>>;
384
461
  changes: Partial<ColumnArrays<InferUpdateChanges<TTable>>>;
385
462
  }): Promise<unknown>;
386
463
  delete(input: {
387
- keys: ReadonlyArray<UniqueKeyValue<TTable>>;
464
+ keys: ReadonlyArray<PrimaryKeyValue<TTable>>;
388
465
  }): Promise<unknown>;
389
466
  rows(): Promise<Array<InferRow<TTable>>>;
390
467
  };
391
468
  /** Applies one table's alteration steps onto its current column records. */
392
469
  export declare function applyColumnSteps(record: TableRecord, steps: readonly MigrationStep[], createId: () => string): TableColumnRecord[];
393
470
  export {};
394
- //# sourceMappingURL=schema.d.ts.map