@fabrika/db 0.9.0-dev.7 → 0.9.0-dev.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/db",
3
- "version": "0.9.0-dev.7",
3
+ "version": "0.9.0-dev.9",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -92,9 +92,9 @@
92
92
  "test": "bun test"
93
93
  },
94
94
  "dependencies": {
95
- "@fabrika/auth-core": "0.9.0-dev.7",
96
- "@fabrika/platform": "0.9.0-dev.7",
97
- "@fabrika/platform-node": "0.9.0-dev.7",
95
+ "@fabrika/auth-core": "0.9.0-dev.9",
96
+ "@fabrika/platform": "0.9.0-dev.9",
97
+ "@fabrika/platform-node": "0.9.0-dev.9",
98
98
  "kysely": "0.29.6",
99
99
  "kysely-postgres-js": "5.0.1",
100
100
  "zod": "^3.25.76"
@@ -133,13 +133,23 @@ function introspect(db: Database): { columns: SqliteColumn[]; foreignKeys: Forei
133
133
  * Applies `bundles` (the framework's `fabrika`, then the application's `app`) to a fresh in-memory database and renders
134
134
  * the module for `SCHEMA_FILE` from its application tables. Deterministic for given migrations.
135
135
  */
136
- export async function generateSqliteSchema(bundles: readonly SqliteMigrationBundle[]): Promise<string> {
136
+ export function generateSqliteSchema(bundles: readonly SqliteMigrationBundle[]): Promise<string> {
137
+ return withMigratedSqlite(bundles, (db) => {
138
+ const { columns, foreignKeys } = introspect(db)
139
+ return renderTables(columns, foreignKeys, describeSqlite)
140
+ })
141
+ }
142
+
143
+ /**
144
+ * `read` of a fresh in-memory database with foreign keys enforced and `bundles` applied, as the Durable Object applies
145
+ * them; the database is closed after. `fabrika-check` plans the backup of an application's schema with it.
146
+ */
147
+ export async function withMigratedSqlite<T>(bundles: readonly SqliteMigrationBundle[], read: (db: Database) => T): Promise<T> {
137
148
  const db = new Database(':memory:')
138
149
  try {
139
150
  db.run('PRAGMA foreign_keys = ON')
140
151
  await migrateSqlite(bunTarget(db), bundles)
141
- const { columns, foreignKeys } = introspect(db)
142
- return renderTables(columns, foreignKeys, describeSqlite)
152
+ return read(db)
143
153
  } finally {
144
154
  db.close()
145
155
  }
@@ -1,6 +1,12 @@
1
+ import { Database } from 'bun:sqlite';
1
2
  import { type SqliteMigrationBundle } from './sqlite-migrate';
2
3
  /**
3
4
  * Applies `bundles` (the framework's `fabrika`, then the application's `app`) to a fresh in-memory database and renders
4
5
  * the module for `SCHEMA_FILE` from its application tables. Deterministic for given migrations.
5
6
  */
6
7
  export declare function generateSqliteSchema(bundles: readonly SqliteMigrationBundle[]): Promise<string>;
8
+ /**
9
+ * `read` of a fresh in-memory database with foreign keys enforced and `bundles` applied, as the Durable Object applies
10
+ * them; the database is closed after. `fabrika-check` plans the backup of an application's schema with it.
11
+ */
12
+ export declare function withMigratedSqlite<T>(bundles: readonly SqliteMigrationBundle[], read: (db: Database) => T): Promise<T>;