@telorun/sqlite 0.2.0 → 0.3.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.
@@ -53,6 +53,12 @@ export declare class SqliteSchemaDriver implements SchemaDriver {
53
53
  classifyForeignKeyChange(live: LiveForeignKey): ChangeSafety;
54
54
  classifyAlter(live: LiveColumn, declared: DeclaredColumn): ChangeSafety;
55
55
  classifyCopy(live: LiveColumn, target: DeclaredColumn): ChangeSafety;
56
+ /** SQLite has no ADD CONSTRAINT, so a foreign key exists only as part of the
57
+ * table it was created with — see `createTable`. */
58
+ readonly foreignKeysInCreateTable = true;
59
+ /** `PRAGMA foreign_key_list` reports no name, and there is nowhere to have put
60
+ * one: SQLite does not record a constraint name for a foreign key. */
61
+ readonly namesForeignKeys = false;
56
62
  createTable(schema: string, table: DeclaredTable): string[];
57
63
  addColumn(schema: string, table: string, column: DeclaredColumn): string[];
58
64
  /** Unreachable: `classifyAlter` refuses every in-place column change SQLite
@@ -246,6 +246,12 @@ export class SqliteSchemaDriver {
246
246
  const def = columnDefault(column);
247
247
  return parts.join(" ") + def;
248
248
  }
249
+ /** SQLite has no ADD CONSTRAINT, so a foreign key exists only as part of the
250
+ * table it was created with — see `createTable`. */
251
+ foreignKeysInCreateTable = true;
252
+ /** `PRAGMA foreign_key_list` reports no name, and there is nowhere to have put
253
+ * one: SQLite does not record a constraint name for a foreign key. */
254
+ namesForeignKeys = false;
249
255
  createTable(schema, table) {
250
256
  const parts = table.columns.map((column) => this.#columnDefinition(column));
251
257
  // Foreign keys are part of the table in SQLite — there is no ADD CONSTRAINT
@@ -9,11 +9,11 @@ import { type DeclaredTable, type RawTable } from "@telorun/sql";
9
9
  */
10
10
  export declare class SqliteTableResource implements ResourceInstance {
11
11
  readonly declaration: DeclaredTable;
12
- constructor(raw: RawTable);
12
+ constructor(raw: RawTable, ctx: ResourceContext);
13
13
  /** The physical table name, read by consumers that build statements against
14
14
  * it (`self.table.table` in a repository's template). */
15
15
  get table(): string;
16
16
  snapshot(): Record<string, unknown>;
17
17
  }
18
18
  export declare function register(): void;
19
- export declare function create(resource: RawTable, _ctx: ResourceContext): Promise<SqliteTableResource>;
19
+ export declare function create(resource: RawTable, ctx: ResourceContext): Promise<SqliteTableResource>;
@@ -1,4 +1,4 @@
1
- import { normalizeTable } from "@telorun/sql";
1
+ import { normalizeTable, tableReferenceResolver, } from "@telorun/sql";
2
2
  /**
3
3
  * `SQLite.Table` — one physical table, declared rather than migrated to.
4
4
  *
@@ -8,8 +8,8 @@ import { normalizeTable } from "@telorun/sql";
8
8
  */
9
9
  export class SqliteTableResource {
10
10
  declaration;
11
- constructor(raw) {
12
- this.declaration = normalizeTable(raw);
11
+ constructor(raw, ctx) {
12
+ this.declaration = normalizeTable(raw, tableReferenceResolver(ctx, "SQLite.Table", raw.table));
13
13
  }
14
14
  /** The physical table name, read by consumers that build statements against
15
15
  * it (`self.table.table` in a repository's template). */
@@ -21,6 +21,6 @@ export class SqliteTableResource {
21
21
  }
22
22
  }
23
23
  export function register() { }
24
- export async function create(resource, _ctx) {
25
- return new SqliteTableResource(resource);
24
+ export async function create(resource, ctx) {
25
+ return new SqliteTableResource(resource, ctx);
26
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/sqlite",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Telo SQLite.Connection — SQLite backend for the Sql.Connection abstract (better-sqlite3 / bun:sqlite, transactional DDL).",
5
5
  "keywords": [
6
6
  "telo",
@@ -44,14 +44,14 @@
44
44
  "dependencies": {
45
45
  "better-sqlite3": "^12.8.0",
46
46
  "kysely": "^0.28.15",
47
- "@telorun/sql": "0.22.0"
47
+ "@telorun/sql": "0.23.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/better-sqlite3": "^7.0.0",
51
51
  "@types/bun": "^1.3.10",
52
52
  "@types/node": "^20.0.0",
53
53
  "typescript": "^5.0.0",
54
- "@telorun/sdk": "0.79.0"
54
+ "@telorun/sdk": "0.82.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@telorun/sdk": "*"
@@ -292,6 +292,14 @@ export class SqliteSchemaDriver implements SchemaDriver {
292
292
  return parts.join(" ") + def;
293
293
  }
294
294
 
295
+ /** SQLite has no ADD CONSTRAINT, so a foreign key exists only as part of the
296
+ * table it was created with — see `createTable`. */
297
+ readonly foreignKeysInCreateTable = true;
298
+
299
+ /** `PRAGMA foreign_key_list` reports no name, and there is nowhere to have put
300
+ * one: SQLite does not record a constraint name for a foreign key. */
301
+ readonly namesForeignKeys = false;
302
+
295
303
  createTable(schema: string, table: DeclaredTable): string[] {
296
304
  const parts = table.columns.map((column) => this.#columnDefinition(column));
297
305
  // Foreign keys are part of the table in SQLite — there is no ADD CONSTRAINT
@@ -1,5 +1,10 @@
1
1
  import type { ResourceContext, ResourceInstance } from "@telorun/sdk";
2
- import { normalizeTable, type DeclaredTable, type RawTable } from "@telorun/sql";
2
+ import {
3
+ normalizeTable,
4
+ tableReferenceResolver,
5
+ type DeclaredTable,
6
+ type RawTable,
7
+ } from "@telorun/sql";
3
8
 
4
9
  /**
5
10
  * `SQLite.Table` — one physical table, declared rather than migrated to.
@@ -11,8 +16,8 @@ import { normalizeTable, type DeclaredTable, type RawTable } from "@telorun/sql"
11
16
  export class SqliteTableResource implements ResourceInstance {
12
17
  readonly declaration: DeclaredTable;
13
18
 
14
- constructor(raw: RawTable) {
15
- this.declaration = normalizeTable(raw);
19
+ constructor(raw: RawTable, ctx: ResourceContext) {
20
+ this.declaration = normalizeTable(raw, tableReferenceResolver(ctx, "SQLite.Table", raw.table));
16
21
  }
17
22
 
18
23
  /** The physical table name, read by consumers that build statements against
@@ -30,7 +35,7 @@ export function register(): void {}
30
35
 
31
36
  export async function create(
32
37
  resource: RawTable,
33
- _ctx: ResourceContext,
38
+ ctx: ResourceContext,
34
39
  ): Promise<SqliteTableResource> {
35
- return new SqliteTableResource(resource);
40
+ return new SqliteTableResource(resource, ctx);
36
41
  }