@fougere/adapter-sql 0.9.3-alpha.0 → 0.11.0-alpha.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 (202) hide show
  1. package/dist/check.d.ts +1 -1
  2. package/dist/check.d.ts.map +1 -1
  3. package/dist/{crud.d.ts → crud/SqlStorage.d.ts} +3 -7
  4. package/dist/crud/SqlStorage.d.ts.map +1 -0
  5. package/dist/{crud.js → crud/SqlStorage.js} +5 -8
  6. package/dist/crud/SqlStorage.js.map +1 -0
  7. package/dist/crud/StorageFactoryOptions.d.ts +5 -0
  8. package/dist/crud/StorageFactoryOptions.d.ts.map +1 -0
  9. package/dist/crud/StorageFactoryOptions.js +2 -0
  10. package/dist/crud/StorageFactoryOptions.js.map +1 -0
  11. package/dist/ddl/GenerateOptions.d.ts +8 -0
  12. package/dist/ddl/GenerateOptions.d.ts.map +1 -0
  13. package/dist/ddl/GenerateOptions.js +2 -0
  14. package/dist/ddl/GenerateOptions.js.map +1 -0
  15. package/dist/{ddl.d.ts → ddl/SqlSink.d.ts} +6 -10
  16. package/dist/ddl/SqlSink.d.ts.map +1 -0
  17. package/dist/{ddl.js → ddl/SqlSink.js} +6 -7
  18. package/dist/ddl/SqlSink.js.map +1 -0
  19. package/dist/{dialect.d.ts → dialect/Dialect.d.ts} +3 -4
  20. package/dist/dialect/Dialect.d.ts.map +1 -0
  21. package/dist/{dialect.js → dialect/Dialect.js} +1 -1
  22. package/dist/dialect/Dialect.js.map +1 -0
  23. package/dist/dialect/DialectName.d.ts +2 -0
  24. package/dist/dialect/DialectName.d.ts.map +1 -0
  25. package/dist/dialect/DialectName.js +2 -0
  26. package/dist/dialect/DialectName.js.map +1 -0
  27. package/dist/{diff.d.ts → diff/Change.d.ts} +7 -7
  28. package/dist/diff/Change.d.ts.map +1 -0
  29. package/dist/{diff.js → diff/Change.js} +6 -7
  30. package/dist/diff/Change.js.map +1 -0
  31. package/dist/diff/SchemaState.d.ts +6 -0
  32. package/dist/diff/SchemaState.d.ts.map +1 -0
  33. package/dist/diff/SchemaState.js +11 -0
  34. package/dist/diff/SchemaState.js.map +1 -0
  35. package/dist/drift.d.ts +1 -1
  36. package/dist/drift.d.ts.map +1 -1
  37. package/dist/drift.js +1 -1
  38. package/dist/drift.js.map +1 -1
  39. package/dist/fields/Engine.d.ts +4 -0
  40. package/dist/fields/Engine.d.ts.map +1 -0
  41. package/dist/fields/Engine.js +2 -0
  42. package/dist/fields/Engine.js.map +1 -0
  43. package/dist/fields/SqlField.d.ts +6 -0
  44. package/dist/fields/SqlField.d.ts.map +1 -0
  45. package/dist/fields/SqlField.js +2 -0
  46. package/dist/fields/SqlField.js.map +1 -0
  47. package/dist/{fields.d.ts → fields/SqlFields.d.ts} +2 -9
  48. package/dist/fields/SqlFields.d.ts.map +1 -0
  49. package/dist/{fields.js → fields/SqlFields.js} +2 -2
  50. package/dist/fields/SqlFields.js.map +1 -0
  51. package/dist/index.d.ts +23 -16
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +10 -9
  54. package/dist/index.js.map +1 -1
  55. package/dist/order/FkEdge.d.ts +7 -0
  56. package/dist/order/FkEdge.d.ts.map +1 -0
  57. package/dist/order/FkEdge.js +2 -0
  58. package/dist/order/FkEdge.js.map +1 -0
  59. package/dist/{order.d.ts → order/TableOrder.d.ts} +3 -10
  60. package/dist/order/TableOrder.d.ts.map +1 -0
  61. package/dist/{order.js → order/TableOrder.js} +1 -1
  62. package/dist/order/TableOrder.js.map +1 -0
  63. package/dist/{query.d.ts → query/QueryEvent.d.ts} +1 -7
  64. package/dist/query/QueryEvent.d.ts.map +1 -0
  65. package/dist/query/QueryEvent.js +2 -0
  66. package/dist/query/QueryEvent.js.map +1 -0
  67. package/dist/query/QuerySink.d.ts +8 -0
  68. package/dist/query/QuerySink.d.ts.map +1 -0
  69. package/dist/{query.js → query/QuerySink.js} +1 -1
  70. package/dist/query/QuerySink.js.map +1 -0
  71. package/dist/source/Setup.d.ts +4 -0
  72. package/dist/source/Setup.d.ts.map +1 -0
  73. package/dist/source/Setup.js +2 -0
  74. package/dist/source/Setup.js.map +1 -0
  75. package/dist/{source.d.ts → source/SqlSource.d.ts} +11 -15
  76. package/dist/source/SqlSource.d.ts.map +1 -0
  77. package/dist/{source.js → source/SqlSource.js} +12 -9
  78. package/dist/source/SqlSource.js.map +1 -0
  79. package/dist/source/SqlSourceOptions.d.ts +8 -0
  80. package/dist/source/SqlSourceOptions.d.ts.map +1 -0
  81. package/dist/source/SqlSourceOptions.js +2 -0
  82. package/dist/source/SqlSourceOptions.js.map +1 -0
  83. package/dist/{sqlite.d.ts → sqlite/SqliteSource.d.ts} +3 -6
  84. package/dist/sqlite/SqliteSource.d.ts.map +1 -0
  85. package/dist/{sqlite.js → sqlite/SqliteSource.js} +7 -8
  86. package/dist/sqlite/SqliteSource.js.map +1 -0
  87. package/dist/sqlite/SqliteSourceOptions.d.ts +6 -0
  88. package/dist/sqlite/SqliteSourceOptions.d.ts.map +1 -0
  89. package/dist/sqlite/SqliteSourceOptions.js +2 -0
  90. package/dist/sqlite/SqliteSourceOptions.js.map +1 -0
  91. package/dist/sqlite/index.d.ts +3 -0
  92. package/dist/sqlite/index.d.ts.map +1 -0
  93. package/dist/sqlite/index.js +2 -0
  94. package/dist/sqlite/index.js.map +1 -0
  95. package/dist/{step.d.ts → step/Plan.d.ts} +6 -28
  96. package/dist/step/Plan.d.ts.map +1 -0
  97. package/dist/{step.js → step/Plan.js} +5 -6
  98. package/dist/step/Plan.js.map +1 -0
  99. package/dist/step/PlanOptions.d.ts +8 -0
  100. package/dist/step/PlanOptions.d.ts.map +1 -0
  101. package/dist/step/PlanOptions.js +2 -0
  102. package/dist/step/PlanOptions.js.map +1 -0
  103. package/dist/step/Refusal.d.ts +7 -0
  104. package/dist/step/Refusal.d.ts.map +1 -0
  105. package/dist/step/Refusal.js +2 -0
  106. package/dist/step/Refusal.js.map +1 -0
  107. package/dist/step/StepChange.d.ts +12 -0
  108. package/dist/step/StepChange.d.ts.map +1 -0
  109. package/dist/step/StepChange.js +2 -0
  110. package/dist/step/StepChange.js.map +1 -0
  111. package/dist/table/AppLike.d.ts +12 -0
  112. package/dist/table/AppLike.d.ts.map +1 -0
  113. package/dist/table/AppLike.js +2 -0
  114. package/dist/table/AppLike.js.map +1 -0
  115. package/dist/table/ColumnDef.d.ts +34 -0
  116. package/dist/table/ColumnDef.d.ts.map +1 -0
  117. package/dist/table/ColumnDef.js +2 -0
  118. package/dist/table/ColumnDef.js.map +1 -0
  119. package/dist/table/ColumnReference.d.ts +6 -0
  120. package/dist/table/ColumnReference.d.ts.map +1 -0
  121. package/dist/table/ColumnReference.js +2 -0
  122. package/dist/table/ColumnReference.js.map +1 -0
  123. package/dist/table/EntityEntry.d.ts +7 -0
  124. package/dist/table/EntityEntry.d.ts.map +1 -0
  125. package/dist/table/EntityEntry.js +2 -0
  126. package/dist/table/EntityEntry.js.map +1 -0
  127. package/dist/table/FrondLike.d.ts +6 -0
  128. package/dist/table/FrondLike.d.ts.map +1 -0
  129. package/dist/table/FrondLike.js +2 -0
  130. package/dist/table/FrondLike.js.map +1 -0
  131. package/dist/table/HostedNames.d.ts +8 -0
  132. package/dist/table/HostedNames.d.ts.map +1 -0
  133. package/dist/table/HostedNames.js +2 -0
  134. package/dist/table/HostedNames.js.map +1 -0
  135. package/dist/table/RelationResolve.d.ts +12 -0
  136. package/dist/table/RelationResolve.d.ts.map +1 -0
  137. package/dist/table/RelationResolve.js +2 -0
  138. package/dist/table/RelationResolve.js.map +1 -0
  139. package/dist/table/TableDef.d.ts +29 -0
  140. package/dist/table/TableDef.d.ts.map +1 -0
  141. package/dist/{table.js → table/TableDef.js} +3 -4
  142. package/dist/table/TableDef.js.map +1 -0
  143. package/package.json +6 -6
  144. package/src/check.ts +1 -1
  145. package/src/{crud.ts → crud/SqlStorage.ts} +6 -13
  146. package/src/crud/StorageFactoryOptions.ts +4 -0
  147. package/src/ddl/GenerateOptions.ts +8 -0
  148. package/src/{ddl.ts → ddl/SqlSink.ts} +8 -21
  149. package/src/{dialect.ts → dialect/Dialect.ts} +2 -4
  150. package/src/dialect/DialectName.ts +1 -0
  151. package/src/{diff.ts → diff/Change.ts} +10 -16
  152. package/src/diff/SchemaState.ts +13 -0
  153. package/src/drift.ts +2 -2
  154. package/src/fields/Engine.ts +4 -0
  155. package/src/fields/SqlField.ts +6 -0
  156. package/src/{fields.ts → fields/SqlFields.ts} +5 -10
  157. package/src/index.ts +23 -23
  158. package/src/order/FkEdge.ts +7 -0
  159. package/src/{order.ts → order/TableOrder.ts} +2 -10
  160. package/src/query/QueryEvent.ts +16 -0
  161. package/src/{query.ts → query/QuerySink.ts} +2 -17
  162. package/src/source/Setup.ts +4 -0
  163. package/src/{source.ts → source/SqlSource.ts} +14 -20
  164. package/src/source/SqlSourceOptions.ts +8 -0
  165. package/src/{sqlite.ts → sqlite/SqliteSource.ts} +7 -12
  166. package/src/sqlite/SqliteSourceOptions.ts +6 -0
  167. package/src/sqlite/index.ts +2 -0
  168. package/src/{step.ts → step/Plan.ts} +8 -27
  169. package/src/step/PlanOptions.ts +8 -0
  170. package/src/step/Refusal.ts +6 -0
  171. package/src/step/StepChange.ts +4 -0
  172. package/src/table/AppLike.ts +10 -0
  173. package/src/table/ColumnDef.ts +34 -0
  174. package/src/table/ColumnReference.ts +5 -0
  175. package/src/table/EntityEntry.ts +7 -0
  176. package/src/table/FrondLike.ts +6 -0
  177. package/src/table/HostedNames.ts +7 -0
  178. package/src/table/RelationResolve.ts +12 -0
  179. package/src/{table.ts → table/TableDef.ts} +10 -77
  180. package/dist/crud.d.ts.map +0 -1
  181. package/dist/crud.js.map +0 -1
  182. package/dist/ddl.d.ts.map +0 -1
  183. package/dist/ddl.js.map +0 -1
  184. package/dist/dialect.d.ts.map +0 -1
  185. package/dist/dialect.js.map +0 -1
  186. package/dist/diff.d.ts.map +0 -1
  187. package/dist/diff.js.map +0 -1
  188. package/dist/fields.d.ts.map +0 -1
  189. package/dist/fields.js.map +0 -1
  190. package/dist/order.d.ts.map +0 -1
  191. package/dist/order.js.map +0 -1
  192. package/dist/query.d.ts.map +0 -1
  193. package/dist/query.js.map +0 -1
  194. package/dist/source.d.ts.map +0 -1
  195. package/dist/source.js.map +0 -1
  196. package/dist/sqlite.d.ts.map +0 -1
  197. package/dist/sqlite.js.map +0 -1
  198. package/dist/step.d.ts.map +0 -1
  199. package/dist/step.js.map +0 -1
  200. package/dist/table.d.ts +0 -97
  201. package/dist/table.d.ts.map +0 -1
  202. package/dist/table.js.map +0 -1
@@ -0,0 +1,34 @@
1
+ import { type ShapeType } from '@fougere/schema';
2
+ import { type ShapeBounds } from '../check.js';
3
+ import { type SqlField } from '../fields/SqlField.js';
4
+ import type { ColumnReference } from './ColumnReference.js';
5
+ /** One column, described by the axes — plus, at most, what the entity stated for sql. */
6
+ export interface ColumnDef {
7
+ /** Field key on the entity. */
8
+ field: string;
9
+ /** SQL column name (snake_case). */
10
+ name: string;
11
+ /** What every projection here dispatches on — a `date()` and a bounded set included. */
12
+ type?: ShapeType;
13
+ nullable: boolean;
14
+ primary: boolean;
15
+ /** A literal default (`lifecycle.create.value`), when the field declares one. */
16
+ default?: unknown;
17
+ /** A {@link Unique} of one — realized as a column constraint the database enforces. */
18
+ unique?: boolean;
19
+ /** `role.index` — realized as a separate `CREATE INDEX`, never a constraint. */
20
+ index?: boolean;
21
+ /**
22
+ * What the shape bounds beyond its type — `oneOf`, `min`, `max`. Realized as a
23
+ * `CHECK`, so the rule holds on every write and not only at the façade.
24
+ */
25
+ bounds?: ShapeBounds;
26
+ /** The FK target, from `role.relation` when it's a `ref()` (kind `'one'`). */
27
+ references?: ColumnReference;
28
+ /**
29
+ * What the entity stated for THIS adapter — never an axis. It says how the column is
30
+ * realized here; drop it and the column is still describable.
31
+ */
32
+ stated?: SqlField;
33
+ }
34
+ //# sourceMappingURL=ColumnDef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColumnDef.d.ts","sourceRoot":"","sources":["../../src/table/ColumnDef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,yFAAyF;AACzF,MAAM,WAAW,SAAS;IACxB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uFAAuF;IACvF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ColumnDef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColumnDef.js","sourceRoot":"","sources":["../../src/table/ColumnDef.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export interface ColumnReference {
2
+ table: string;
3
+ column: string;
4
+ onDelete?: 'cascade' | 'restrict' | 'set null';
5
+ }
6
+ //# sourceMappingURL=ColumnReference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColumnReference.d.ts","sourceRoot":"","sources":["../../src/table/ColumnReference.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;CAChD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ColumnReference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColumnReference.js","sourceRoot":"","sources":["../../src/table/ColumnReference.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { type SchemaView } from '@fougere/schema';
2
+ export interface EntityEntry {
3
+ name: string;
4
+ /** A live class in-process, or one rebuilt from the card of a frond that never crossed. */
5
+ entityClass: SchemaView;
6
+ }
7
+ //# sourceMappingURL=EntityEntry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityEntry.d.ts","sourceRoot":"","sources":["../../src/table/EntityEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,WAAW,EAAE,UAAU,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=EntityEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityEntry.js","sourceRoot":"","sources":["../../src/table/EntityEntry.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { EntityEntry } from './EntityEntry.js';
2
+ export interface FrondLike {
3
+ name: string;
4
+ entities: EntityEntry[];
5
+ }
6
+ //# sourceMappingURL=FrondLike.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FrondLike.d.ts","sourceRoot":"","sources":["../../src/table/FrondLike.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=FrondLike.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FrondLike.js","sourceRoot":"","sources":["../../src/table/FrondLike.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ /** The two name sets a cross-source batch is read against — see {@link referenceFor}. */
2
+ export interface HostedNames {
3
+ /** Registration names in THIS batch. */
4
+ here: ReadonlySet<string>;
5
+ /** Registration names the app hosts in another source — see {@link AppLike.elsewhere}. */
6
+ elsewhere: ReadonlySet<string>;
7
+ }
8
+ //# sourceMappingURL=HostedNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostedNames.d.ts","sourceRoot":"","sources":["../../src/table/HostedNames.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1B,0FAA0F;IAC1F,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=HostedNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostedNames.js","sourceRoot":"","sources":["../../src/table/HostedNames.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { type SchemaView } from '@fougere/schema';
2
+ import type { HostedNames } from './HostedNames.js';
3
+ /** How a `ref()` field's target table+column is resolved — see {@link referenceFor}. */
4
+ export interface RelationResolve {
5
+ /** Same resolver used for every entity's own table (default or a custom `tableName`). */
6
+ resolve: (name: string) => string;
7
+ /** Live entity class → its already-resolved table name, reused instead of re-derived. */
8
+ tableNameOf?: Map<SchemaView, string>;
9
+ /** Which entities this batch holds and which live in another source — decided by NAME. */
10
+ hosted?: HostedNames;
11
+ }
12
+ //# sourceMappingURL=RelationResolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationResolve.d.ts","sourceRoot":"","sources":["../../src/table/RelationResolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,wFAAwF;AACxF,MAAM,WAAW,eAAe;IAC9B,yFAAyF;IACzF,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,yFAAyF;IACzF,WAAW,CAAC,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACtC,0FAA0F;IAC1F,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RelationResolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationResolve.js","sourceRoot":"","sources":["../../src/table/RelationResolve.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import { type SchemaView } from '@fougere/schema';
2
+ import type { ColumnDef } from './ColumnDef.js';
3
+ import type { RelationResolve } from './RelationResolve.js';
4
+ import type { AppLike } from './AppLike.js';
5
+ export interface TableDef {
6
+ name: string;
7
+ columns: ColumnDef[];
8
+ /** PK column names when the key is composite — empty for a simple key. */
9
+ compositePrimary: string[];
10
+ /** Column groups unique together, from `entity(fields, { unique: [...] })`. */
11
+ uniqueGroups: string[][];
12
+ }
13
+ /** camelCase → snake_case */
14
+ export declare function toSnakeCase(str: string): string;
15
+ /** Describe one entity as a table — the single reader of the axes. */
16
+ export declare function toTable(tableName: string, schema: SchemaView, relations?: RelationResolve): TableDef;
17
+ /**
18
+ * Is this column part of a key? MySQL and SQL Server refuse an unbounded text column in a primary
19
+ * key or an index, so the dialect needs to know.
20
+ */
21
+ export declare function isKeyed(table: TableDef, column: ColumnDef): boolean;
22
+ /** camelCase → snake_case + plural */
23
+ export declare function toTableName(name: string): string;
24
+ /**
25
+ * Every entity an app hosts, as FK-aware tables — the shared middle step behind `generateSQL` (a
26
+ * from-scratch create pass) and `desiredTables` (the diff's target state).
27
+ */
28
+ export declare function toTables(app: AppLike, resolve: (name: string) => string): TableDef[];
29
+ //# sourceMappingURL=TableDef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableDef.d.ts","sourceRoot":"","sources":["../../src/table/TableDef.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,0EAA0E;IAC1E,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,+EAA+E;IAC/E,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;CAC1B;AAED,6BAA6B;AAC7B,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AA8FD,sEAAsE;AACtE,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,eAAe,GAAG,QAAQ,CA6BpG;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAKnE;AAID,sCAAsC;AACtC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AA+BD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,QAAQ,EAAE,CAOpF"}
@@ -1,8 +1,7 @@
1
1
  import { Lifecycle, Role } from '@fougere/schema';
2
- /** Entity → table description, with no SQL in sight. */
3
2
  import { Shapes, lowerFirst } from '@fougere/schema';
4
- import { boundsOf } from './check.js';
5
- import { sqlEntries } from './fields.js';
3
+ import { boundsOf } from '../check.js';
4
+ import { sqlEntries } from '../fields/SqlFields.js';
6
5
  /** camelCase → snake_case */
7
6
  export function toSnakeCase(str) {
8
7
  return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
@@ -177,4 +176,4 @@ export function toTables(app, resolve) {
177
176
  return entries.map((entry) => toTable(resolve(entry.name), entry.entityClass, { resolve, tableNameOf, hosted }));
178
177
  }
179
178
  // ─── Ordering — a referenced table before its referrer ─────────────────────
180
- //# sourceMappingURL=table.js.map
179
+ //# sourceMappingURL=TableDef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableDef.js","sourceRoot":"","sources":["../../src/table/TableDef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAA+B,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAiBpD,6BAA6B;AAC7B,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAED;;;GAGG;AACH,SAAS,QAAQ,CAAC,KAAY;IAC5B,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC;AACtC,CAAC;AAED,uCAAuC;AACvC,SAAS,eAAe,CAAC,MAA2B;IAClD,IAAI,OAAO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C,IAAI,CAAC,QAAQ,CAAC;YAAE,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAY,EAAE,OAAiC;IACtE,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAqB,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAClH,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS;QAC1B,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE;QACtH,CAAC,CAAC,SAAS,CAAC;IACd,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AACnH,CAAC;AAED,8EAA8E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fougere/adapter-sql",
3
- "version": "0.9.3-alpha.0",
3
+ "version": "0.11.0-alpha.0",
4
4
  "description": "Entity → SQL tables through Kysely (SQLite, PostgreSQL, MySQL, SQL Server).",
5
5
  "keywords": [
6
6
  "fougere",
@@ -28,8 +28,8 @@
28
28
  "import": "./dist/index.js"
29
29
  },
30
30
  "./sqlite": {
31
- "types": "./dist/sqlite.d.ts",
32
- "import": "./dist/sqlite.js"
31
+ "types": "./dist/sqlite/index.d.ts",
32
+ "import": "./dist/sqlite/index.js"
33
33
  }
34
34
  },
35
35
  "files": [
@@ -39,8 +39,8 @@
39
39
  "dependencies": {
40
40
  "better-sqlite3": "^13.0.3",
41
41
  "dequal": "^2.0.3",
42
- "@fougere/core": "0.9.3-alpha.0",
43
- "@fougere/schema": "0.9.3-alpha.0"
42
+ "@fougere/core": "0.11.0-alpha.0",
43
+ "@fougere/schema": "0.11.0-alpha.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "kysely": ">=0.28.17"
@@ -49,7 +49,7 @@
49
49
  "@types/better-sqlite3": "^7.6.13",
50
50
  "@types/node": "^22.0.0",
51
51
  "kysely": "^0.28.17",
52
- "@fougere/core": "0.9.3-alpha.0"
52
+ "@fougere/core": "0.11.0-alpha.0"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"
package/src/check.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Shape → CHECK constraints. */
2
2
  import { sql, type Expression, type SqlBool } from 'kysely';
3
- import type { ColumnDef } from './table.js';
3
+ import type { ColumnDef } from './table/ColumnDef.js';
4
4
 
5
5
  /** What a column's shape can be checked for, beyond its type. */
6
6
  export interface ShapeBounds {
@@ -1,13 +1,12 @@
1
1
  import { Lifecycle, Role } from '@fougere/schema';
2
- /** SqlStorage — per-entity storage over Kysely, one implementation for every engine. */
3
2
  import { sql, type Kysely } from 'kysely';
4
3
  import { applyCreate, applyUpdate, type Fields, type SchemaView } from '@fougere/schema';
5
- import { toTable, toTableName, type TableDef } from './table.js';
6
- import { resolveDialect, type Dialect, type DialectName } from './dialect.js';
7
- // The contract entry and not the main one: `FougereError` crosses a process boundary and
8
- // lives there for that reason, and this package must not drag the boot to raise one.
4
+ import { toTable, toTableName, type TableDef } from '../table/TableDef.js';
5
+ import { resolveDialect, type Dialect } from '../dialect/Dialect.js';
6
+ import { type DialectName } from '../dialect/DialectName.js';
9
7
  import { comparisonOf, comparisonsIn, ErrorCode, FougereError, type Comparison } from '@fougere/core/contract';
10
- import { codecsOf, type ValueCodec } from './values.js';
8
+ import { codecsOf, type ValueCodec } from '../values.js';
9
+ import type { StorageFactoryOptions } from './StorageFactoryOptions.js';
11
10
 
12
11
  /** ListOptions — duplicated from @fougere/core to avoid a runtime dep. */
13
12
  interface ListOptions {
@@ -169,7 +168,7 @@ export class SqlStorage {
169
168
  // A criterion may name a SET — `where: { id: [a, b, c] }` is `IN`, one query for a
170
169
  // whole page. Without it a relation had no batch form at all: the GraphQL `one`
171
170
  // resolver read row by row (50 calls for a page of 50, measured), while its `many`
172
- // dual already went through this same door. An empty set matches nothing, said in
171
+ // dual already went through this same facade. An empty set matches nothing, said in
173
172
  // SQL rather than by returning the whole table.
174
173
  private whereAll<Q extends { where(a: any, b: any, c: any): Q }>(query: Q, criteria: Record<string, unknown>): Q {
175
174
  return Object.entries(criteria).reduce((q, [key, value]) => {
@@ -518,12 +517,6 @@ export class SqlStorage {
518
517
  }
519
518
  }
520
519
 
521
-
522
- export interface StorageFactoryOptions {
523
- /** Override table name resolution. Default: camelCase → snake_case + 's'. */
524
- tableName?: (entityName: string) => string;
525
- }
526
-
527
520
  /** Create a StorageFactory backed by Kysely — same call shape on every engine. */
528
521
  export function createStorageFactory(db: Kysely<any>, options?: StorageFactoryOptions, dialect: DialectName = 'sqlite') {
529
522
  const resolve = options?.tableName ?? toTableName;
@@ -0,0 +1,4 @@
1
+ export interface StorageFactoryOptions {
2
+ /** Override table name resolution. Default: camelCase → snake_case + 's'. */
3
+ tableName?: (entityName: string) => string;
4
+ }
@@ -0,0 +1,8 @@
1
+ import { type DialectName } from '../dialect/DialectName.js';
2
+
3
+ export interface GenerateOptions {
4
+ /** Override table name resolution. Default: camelCase → snake_case + 's'. */
5
+ tableName?: (entityName: string) => string;
6
+ /** Target engine. Default: sqlite. */
7
+ dialect?: DialectName;
8
+ }
@@ -1,4 +1,3 @@
1
- /** DDL — the table description, rendered as SQL. */
2
1
  import {
3
2
  Kysely,
4
3
  DummyDriver,
@@ -8,19 +7,14 @@ import {
8
7
  MysqlAdapter, MysqlQueryCompiler, MysqlIntrospector,
9
8
  MssqlAdapter, MssqlQueryCompiler, MssqlIntrospector,
10
9
  } from 'kysely';
11
- import {
12
- isKeyed,
13
- toTableName,
14
- toTables,
15
- type AppLike,
16
- type ColumnDef,
17
- type TableDef,
18
- } from './table.js';
19
- import { orderTables } from './order.js';
20
- import { columnTypeFor, resolveDialect, type DialectName } from './dialect.js';
21
- import { checkFor } from './check.js';
22
-
23
- // ─── Compile-only engines ──────────────────────────
10
+ import { type AppLike } from '../table/AppLike.js';
11
+ import { type ColumnDef } from '../table/ColumnDef.js';
12
+ import { isKeyed, toTableName, toTables, type TableDef } from '../table/TableDef.js';
13
+ import { orderTables } from '../order/TableOrder.js';
14
+ import { columnTypeFor, resolveDialect } from '../dialect/Dialect.js';
15
+ import { type DialectName } from '../dialect/DialectName.js';
16
+ import { checkFor } from '../check.js';
17
+ import type { GenerateOptions } from './GenerateOptions.js';
24
18
 
25
19
  const parts = {
26
20
  sqlite: [SqliteAdapter, SqliteQueryCompiler, SqliteIntrospector],
@@ -139,13 +133,6 @@ export function addForeignKeyConstraintSQL(table: TableDef, column: ColumnDef, d
139
133
 
140
134
  // ─── App-wide generation ───────────────────────────
141
135
 
142
- export interface GenerateOptions {
143
- /** Override table name resolution. Default: camelCase → snake_case + 's'. */
144
- tableName?: (entityName: string) => string;
145
- /** Target engine. Default: sqlite. */
146
- dialect?: DialectName;
147
- }
148
-
149
136
  /**
150
137
  * `CREATE TABLE` for every entity the app hosts — scanned frond entities plus auth runtime
151
138
  * entities when present.
@@ -1,7 +1,5 @@
1
- /** Dialect — the only place that speaks SQL. */
2
- import type { ColumnDef } from './table.js';
3
-
4
- export type DialectName = 'sqlite' | 'pg' | 'mysql' | 'mssql';
1
+ import type { ColumnDef } from '../table/ColumnDef.js';
2
+ import type { DialectName } from './DialectName.js';
5
3
 
6
4
  export interface Dialect {
7
5
  name: DialectName;
@@ -0,0 +1 @@
1
+ export type DialectName = 'sqlite' | 'pg' | 'mysql' | 'mssql';
@@ -1,20 +1,14 @@
1
- /** Diff — what the database is missing, compared to what the entities describe. */
2
1
  import { sql, type Kysely } from 'kysely';
3
- import { addForeignKeyConstraintSQL, compiler, createTableSQL, indexSQL, type GenerateOptions } from './ddl.js';
4
- import { checkFor } from './check.js';
5
- import { columnTypeFor, resolveDialect, type DialectName } from './dialect.js';
6
- import {
7
- isKeyed,
8
- toTables,
9
- toTableName,
10
- type AppLike,
11
- type ColumnDef,
12
- type TableDef,
13
- } from './table.js';
14
- import { orderTables } from './order.js';
15
-
16
- /** What the database actually holds: column names per table. */
17
- export type SchemaState = Map<string, Set<string>>;
2
+ import { type GenerateOptions } from '../ddl/GenerateOptions.js';
3
+ import { addForeignKeyConstraintSQL, compiler, createTableSQL, indexSQL } from '../ddl/SqlSink.js';
4
+ import { checkFor } from '../check.js';
5
+ import { columnTypeFor, resolveDialect } from '../dialect/Dialect.js';
6
+ import { type DialectName } from '../dialect/DialectName.js';
7
+ import { type AppLike } from '../table/AppLike.js';
8
+ import { type ColumnDef } from '../table/ColumnDef.js';
9
+ import { isKeyed, toTableName, toTables, type TableDef } from '../table/TableDef.js';
10
+ import { orderTables } from '../order/TableOrder.js';
11
+ import type { SchemaState } from './SchemaState.js';
18
12
 
19
13
  /** Read the live schema. Only names are needed — an additive pass never inspects types. */
20
14
  export async function actualState(db: Kysely<any>): Promise<SchemaState> {
@@ -0,0 +1,13 @@
1
+ import type { Kysely } from 'kysely';
2
+ /** What the database actually holds: column names per table. */
3
+ export type SchemaState = Map<string, Set<string>>;
4
+
5
+ /** Read the live schema. Only names are needed — an additive pass never inspects types. */
6
+ export async function actualState(db: Kysely<any>): Promise<SchemaState> {
7
+ const state: SchemaState = new Map();
8
+ for (const table of await db.introspection.getTables()) {
9
+ if (table.isView) continue;
10
+ state.set(table.name, new Set(table.columns.map((column) => column.name)));
11
+ }
12
+ return state;
13
+ }
package/src/drift.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** What a table PROMISES and what it now holds, when the two stopped agreeing. */
2
2
  import type { Kysely } from 'kysely';
3
3
 
4
- import type { TableDef } from './table.js';
4
+ import type { TableDef } from './table/TableDef.js';
5
5
 
6
6
  /** One column whose declaration moved and whose table did not follow. */
7
7
  export interface Drift {
@@ -58,7 +58,7 @@ export async function drift(db: Kysely<any>, desired: TableDef[]): Promise<Drift
58
58
  column: column.name,
59
59
  declared: 'required',
60
60
  held: 'nullable',
61
- reason: 'the door refuses what the table would still accept',
61
+ reason: 'the facade refuses what the table would still accept',
62
62
  });
63
63
  }
64
64
  }
@@ -0,0 +1,4 @@
1
+ import ENTRY_FORMAT from '../adapter.schema.json' with { type: 'json' };
2
+
3
+ /** The engines the format names — the one list, read off the file that states it. */
4
+ export type Engine = keyof typeof ENTRY_FORMAT.properties.columnType.properties;
@@ -0,0 +1,6 @@
1
+ import type { Engine } from './Engine.js';
2
+
3
+ export interface SqlField {
4
+ /** The column type to emit, per engine. An engine absent here keeps the shape's own. */
5
+ readonly columnType?: Readonly<Partial<Record<Engine, string>>>;
6
+ }
@@ -3,24 +3,19 @@
3
3
  * no engine and no column type, and must not learn one to let this exist.
4
4
  */
5
5
  import { AdapterFieldValidator, type Shape } from '@fougere/schema';
6
- import ENTRY_FORMAT from './adapter.schema.json' with { type: 'json' };
7
- import type { DialectName } from './dialect.js';
8
-
9
- /** The engines the format names — the one list, read off the file that states it. */
10
- type Engine = keyof typeof ENTRY_FORMAT.properties.columnType.properties;
6
+ import ENTRY_FORMAT from '../adapter.schema.json' with { type: 'json' };
7
+ import type { DialectName } from '../dialect/DialectName.js';
8
+ import type { SqlField } from './SqlField.js';
9
+ import type { Engine } from './Engine.js';
11
10
 
12
11
  /** What sql holds, addressed by field — the shape every augmentation of the registry takes. */
13
12
  export type SqlFields<K extends string> = Readonly<Partial<Record<K, SqlField>>>;
14
13
 
15
- export interface SqlField {
16
- /** The column type to emit, per engine. An engine absent here keeps the shape's own. */
17
- readonly columnType?: Readonly<Partial<Record<Engine, string>>>;
18
- }
19
-
20
14
  /** Judges what an entity states under `adapters.sql`, against the format this adapter ships. */
21
15
  export const sqlEntries = AdapterFieldValidator.of(ENTRY_FORMAT as Shape);
22
16
 
23
17
  type Assert<T extends true> = T;
18
+
24
19
  /** A fifth dialect does not compile until `adapter.schema.json` names it. */
25
20
  type _EnginesMatchDialects = Assert<
26
21
  [Exclude<DialectName, Engine>] extends [never] ? true : false
package/src/index.ts CHANGED
@@ -1,30 +1,30 @@
1
- export { createTableSQL, generateSQL, autoMigrate, compiler } from './ddl.js';
2
- export { onQuery } from './query.js';
3
- export type { QueryEvent, QuerySink } from './query.js';
4
- export { toTable, toTables, toTableName, toSnakeCase } from './table.js';
5
- export { orderTables } from './order.js';
6
- export type {
7
- EntityEntry,
8
- FrondLike,
9
- AppLike,
10
- } from './table.js';
11
- export {
12
- columnTypeFor,
13
- dialects,
14
- } from './dialect.js';
15
- export type { Dialect } from './dialect.js';
16
- export type { SqlField, SqlFields } from './fields.js';
17
- export { SqlStorage, createStorageFactory } from './crud.js';
1
+ export { autoMigrate, compiler, createTableSQL, generateSQL } from './ddl/SqlSink.js';
2
+ export { onQuery } from './query/QuerySink.js';
3
+ export type { QueryEvent } from './query/QueryEvent.js';
4
+ export type { QuerySink } from './query/QuerySink.js';
5
+ export { toSnakeCase, toTable, toTableName, toTables } from './table/TableDef.js';
6
+ export { orderTables } from './order/TableOrder.js';
7
+ export type { AppLike } from './table/AppLike.js';
8
+ export type { EntityEntry } from './table/EntityEntry.js';
9
+ export type { FrondLike } from './table/FrondLike.js';
10
+ export { columnTypeFor, dialects } from './dialect/Dialect.js';
11
+ export type { Dialect } from './dialect/Dialect.js';
12
+ export type { SqlField } from './fields/SqlField.js';
13
+ export type { SqlFields } from './fields/SqlFields.js';
14
+ export { SqlStorage, createStorageFactory } from './crud/SqlStorage.js';
18
15
  export { codecsOf } from './values.js';
19
16
  // The driver this package owns is NOT here: `better-sqlite3` is native and `node:fs` is a
20
17
  // builtin, and an index that re-exported them made the whole adapter unreachable from a
21
18
  // runtime that has neither. It lives at `@fougere/adapter-sql/sqlite`.
22
- export { createKyselySource } from './source.js';
23
- export type { SqlSource } from './source.js';
19
+ export { createKyselySource } from './source/SqlSource.js';
20
+ export type { SqlSource } from './source/SqlSource.js';
24
21
  export { drift } from './drift.js';
25
22
  export type { Drift } from './drift.js';
26
- export { actualState, desiredTables, delta, changeSQL, migrate } from './diff.js';
27
- export type { SchemaState, Change } from './diff.js';
23
+ export { actualState } from './diff/SchemaState.js';
24
+ export { changeSQL, delta, desiredTables, migrate } from './diff/Change.js';
25
+ export type { Change } from './diff/Change.js';
26
+ export type { SchemaState } from './diff/SchemaState.js';
28
27
  // The non-additive half — realised only from a step a human wrote down.
29
- export { planStep, collapseChain, applyStep } from './step.js';
30
- export type { Plan, StepChange } from './step.js';
28
+ export { applyStep, collapseChain, planStep } from './step/Plan.js';
29
+ export type { Plan } from './step/Plan.js';
30
+ export type { StepChange } from './step/StepChange.js';
@@ -0,0 +1,7 @@
1
+ import type { ColumnDef } from '../table/ColumnDef.js';
2
+ import type { TableDef } from '../table/TableDef.js';
3
+
4
+ export interface FkEdge {
5
+ table: TableDef;
6
+ column: ColumnDef;
7
+ }
@@ -1,13 +1,5 @@
1
- /**
2
- * In what order a batch of tables is created — the one question that reads a `TableDef` and
3
- * knows nothing above it: no entity, no axis, no schema.
4
- */
5
- import type { ColumnDef, TableDef } from './table.js';
6
-
7
- export interface FkEdge {
8
- table: TableDef;
9
- column: ColumnDef;
10
- }
1
+ import type { TableDef } from '../table/TableDef.js';
2
+ import type { FkEdge } from './FkEdge.js';
11
3
 
12
4
  export interface TableOrder {
13
5
  /** Tables in dependency order — a `ref()` target always precedes its referrer. */
@@ -0,0 +1,16 @@
1
+ /** One statement this process ran, and what it cost. */
2
+ export interface QueryEvent {
3
+ /** Which storage ran it — a process may open several (`sources:`). */
4
+ storage: string;
5
+ sql: string;
6
+ /** What it read or wrote, or the storage when the statement names no table. */
7
+ subject: string;
8
+ /** `select`, `insert`, `update`, `delete` — its first word, whatever that turns out to be. */
9
+ verb: string;
10
+ /** How MANY parameters, never their values. */
11
+ parameters: number;
12
+ /** Rounded to three decimals: a sub-microsecond statement reports 17 digits otherwise. */
13
+ ms: number;
14
+ failed: boolean;
15
+ at: number;
16
+ }