@hulla/db-sqlite 0.3.1 → 0.3.2

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/dist/engine.d.ts CHANGED
@@ -21,7 +21,7 @@ export declare class SQLiteEngine {
21
21
  physical(table: CompiledTable): string;
22
22
  column(table: CompiledTable, name: string): string;
23
23
  bind(table: CompiledTable, name: string, value: unknown, parameters: SQLiteValue[]): string;
24
- fields(table: CompiledTable, prefix?: string): string;
24
+ fields(table: CompiledTable): string;
25
25
  decode(table: CompiledTable, value: SQLiteRecord): StoredRow;
26
26
  envelope(row: StoredRow, projection?: string[]): {
27
27
  row: StoredRow;
package/dist/engine.js CHANGED
@@ -20,10 +20,15 @@ export class SQLiteEngine {
20
20
  this.driver = driver;
21
21
  this.randomBytes = randomBytes;
22
22
  this.tables = compileSchema(schema);
23
- this.#layout = new Map(this.tables.map((table, index) => [table.name, {
24
- table, physical: quote(`_hulla_t${index}`),
25
- columns: new Map(Object.keys(table.fields).map((name, index) => [name, quote(`c${index}`)])),
26
- }]));
23
+ this.#layout = new Map(this.tables.map((table, index) => {
24
+ const fields = Object.entries(table.fields);
25
+ const columns = new Map(fields.map(([name], index) => [name, quote(`c${index}`)]));
26
+ const selection = fields.map(([name, field]) => {
27
+ const column = columns.get(name);
28
+ return `${field.scalar === "int64" ? `CAST(${column} AS TEXT)` : column} AS ${quote(name)}`;
29
+ }).join(", ");
30
+ return [table.name, { table, physical: quote(`_hulla_t${index}`), columns, fields, selection }];
31
+ }));
27
32
  this.contract = JSON.stringify(schemaDescriptor(schema));
28
33
  if (this.tables.some(table => typeof table.keyGeneration === "object"))
29
34
  throw new TypeError("SQLite custom key handlers are not supported; supply explicit keys with keyGeneration: 'none'");
@@ -56,14 +61,11 @@ export class SQLiteEngine {
56
61
  throw new TypeError("Invalid SQLite wire value");
57
62
  return field.scalar === "int64" ? "CAST(? AS INTEGER)" : "?";
58
63
  }
59
- fields(table, prefix = "") {
60
- return [...this.#layout.get(table.name).columns].map(([name, physical]) => {
61
- const column = prefix + physical;
62
- return `${table.fields[name].scalar === "int64" ? `CAST(${column} AS TEXT)` : column} AS ${quote(name)}`;
63
- }).join(", ");
64
+ fields(table) {
65
+ return this.#layout.get(table.name).selection;
64
66
  }
65
67
  decode(table, value) {
66
- return Object.fromEntries(Object.entries(table.fields).map(([name, field]) => {
68
+ return Object.fromEntries(this.#layout.get(table.name).fields.map(([name, field]) => {
67
69
  let item = value[name];
68
70
  if (item !== null && field.scalar === "json")
69
71
  item = JSON.parse(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hulla/db-sqlite",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "SQLite application instances and platform adapters for Hulla schemas",
6
6
  "exports": {
@@ -55,7 +55,7 @@
55
55
  "LICENSE"
56
56
  ],
57
57
  "peerDependencies": {
58
- "@hulla/db": "^0.3.1"
58
+ "@hulla/db": "^0.3.2"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=22.18.0"