drizzle-orm 0.30.0 → 0.30.1-e01313e
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/expo-sqlite/migrator.cjs +4 -6
- package/expo-sqlite/migrator.cjs.map +1 -1
- package/expo-sqlite/migrator.js +4 -6
- package/expo-sqlite/migrator.js.map +1 -1
- package/libsql/migrator.cjs +29 -2
- package/libsql/migrator.cjs.map +1 -1
- package/libsql/migrator.js +29 -2
- package/libsql/migrator.js.map +1 -1
- package/op-sqlite/driver.cjs +56 -0
- package/op-sqlite/driver.cjs.map +1 -0
- package/op-sqlite/driver.d.cts +5 -0
- package/op-sqlite/driver.d.ts +5 -0
- package/op-sqlite/driver.js +35 -0
- package/op-sqlite/driver.js.map +1 -0
- package/op-sqlite/index.cjs +25 -0
- package/op-sqlite/index.cjs.map +1 -0
- package/op-sqlite/index.d.cts +2 -0
- package/op-sqlite/index.d.ts +2 -0
- package/op-sqlite/index.js +3 -0
- package/op-sqlite/index.js.map +1 -0
- package/op-sqlite/migrator.cjs +90 -0
- package/op-sqlite/migrator.cjs.map +1 -0
- package/op-sqlite/migrator.d.cts +29 -0
- package/op-sqlite/migrator.d.ts +29 -0
- package/op-sqlite/migrator.js +65 -0
- package/op-sqlite/migrator.js.map +1 -0
- package/op-sqlite/session.cjs +130 -0
- package/op-sqlite/session.cjs.map +1 -0
- package/op-sqlite/session.d.cts +46 -0
- package/op-sqlite/session.d.ts +46 -0
- package/op-sqlite/session.js +107 -0
- package/op-sqlite/session.js.map +1 -0
- package/package.json +103 -50
- package/sqlite-core/dialect.cjs +1 -1
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.d.cts +1 -1
- package/sqlite-core/dialect.d.ts +1 -1
- package/sqlite-core/dialect.js +1 -1
- package/sqlite-core/dialect.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/expo-sqlite/migrator.cjs
CHANGED
|
@@ -74,13 +74,11 @@ const useMigrations = (db, migrations) => {
|
|
|
74
74
|
const [state, dispatch] = (0, import_react.useReducer)(fetchReducer, initialState);
|
|
75
75
|
(0, import_react.useEffect)(() => {
|
|
76
76
|
dispatch({ type: "migrating" });
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
} catch (error) {
|
|
77
|
+
migrate(db, migrations).then(() => {
|
|
78
|
+
dispatch({ type: "migrated", payload: true });
|
|
79
|
+
}).catch((error) => {
|
|
82
80
|
dispatch({ type: "error", payload: error });
|
|
83
|
-
}
|
|
81
|
+
});
|
|
84
82
|
}, []);
|
|
85
83
|
return state;
|
|
86
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tfor await (const journalEntry of journal.entries) {\n\t\tconst query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n\t\tif (!query) {\n\t\t\tthrow new Error(`Missing migration: ${journalEntry.tag}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: journalEntry.breakpoints,\n\t\t\t\tfolderMillis: journalEntry.when,\n\t\t\t\thash: '',\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`Failed to parse migration: ${journalEntry.tag}`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: ExpoSQLiteDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = await readMigrationFiles(config);\n\treturn db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error };\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t};\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState };\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload };\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t};\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tfor await (const journalEntry of journal.entries) {\n\t\tconst query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n\t\tif (!query) {\n\t\t\tthrow new Error(`Missing migration: ${journalEntry.tag}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: journalEntry.breakpoints,\n\t\t\t\tfolderMillis: journalEntry.when,\n\t\t\t\thash: '',\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`Failed to parse migration: ${journalEntry.tag}`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: ExpoSQLiteDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = await readMigrationFiles(config);\n\treturn db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error };\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t};\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState };\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload };\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t};\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })\n\t\tmigrate(db, migrations as any).then(() => {\n\t\t\tdispatch({ type: 'migrated', payload: true })\n\t\t}).catch((error) => {\n\t\t\tdispatch({ type: 'error', payload: error as Error })\n\t\t});\n\t}, []);\n\n\treturn state;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AAWtC,eAAe,mBAAmB,EAAE,SAAS,WAAW,GAA8C;AACrG,QAAM,mBAAoC,CAAC;AAE3C,mBAAiB,gBAAgB,QAAQ,SAAS;AACjD,UAAM,QAAQ,WAAW,IAAI,aAAa,IAAI,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE;AAE3E,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM,sBAAsB,aAAa,GAAG,EAAE;AAAA,IACzD;AAEA,QAAI;AACH,YAAM,SAAS,MAAM,MAAM,0BAA0B,EAAE,IAAI,CAAC,OAAO;AAClE,eAAO;AAAA,MACR,CAAC;AAED,uBAAiB,KAAK;AAAA,QACrB,KAAK;AAAA,QACL,KAAK,aAAa;AAAA,QAClB,cAAc,aAAa;AAAA,QAC3B,MAAM;AAAA,MACP,CAAC;AAAA,IACF,QAAQ;AACP,YAAM,IAAI,MAAM,8BAA8B,aAAa,GAAG,EAAE;AAAA,IACjE;AAAA,EACD;AAEA,SAAO;AACR;AAEA,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,MAAM,mBAAmB,MAAM;AAClD,SAAO,GAAG,QAAQ,QAAQ,YAAY,GAAG,OAAO;AACjD;AAYO,MAAM,gBAAgB,CAAC,IAA6B,eAK9C;AACZ,QAAM,eAAsB;AAAA,IAC3B,SAAS;AAAA,IACT,OAAO;AAAA,EACR;AAEA,QAAM,eAAe,CAACA,QAAc,WAA0B;AAC7D,YAAQ,OAAO,MAAM;AAAA,MACpB,KAAK,aAAa;AACjB,eAAO,EAAE,GAAG,aAAa;AAAA,MAC1B;AAAA,MACA,KAAK,YAAY;AAChB,eAAO,EAAE,GAAG,cAAc,SAAS,OAAO,QAAQ;AAAA,MACnD;AAAA,MACA,KAAK,SAAS;AACb,eAAO,EAAE,GAAG,cAAc,OAAO,OAAO,QAAQ;AAAA,MACjD;AAAA,MACA,SAAS;AACR,eAAOA;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAW,cAAc,YAAY;AAE/D,8BAAU,MAAM;AACf,aAAS,EAAE,MAAM,YAAY,CAAC;AAC9B,YAAQ,IAAI,UAAiB,EAAE,KAAK,MAAM;AACzC,eAAS,EAAE,MAAM,YAAY,SAAS,KAAK,CAAC;AAAA,IAC7C,CAAC,EAAE,MAAM,CAAC,UAAU;AACnB,eAAS,EAAE,MAAM,SAAS,SAAS,MAAe,CAAC;AAAA,IACpD,CAAC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACR;","names":["state"]}
|
package/expo-sqlite/migrator.js
CHANGED
|
@@ -50,13 +50,11 @@ const useMigrations = (db, migrations) => {
|
|
|
50
50
|
const [state, dispatch] = useReducer(fetchReducer, initialState);
|
|
51
51
|
useEffect(() => {
|
|
52
52
|
dispatch({ type: "migrating" });
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
} catch (error) {
|
|
53
|
+
migrate(db, migrations).then(() => {
|
|
54
|
+
dispatch({ type: "migrated", payload: true });
|
|
55
|
+
}).catch((error) => {
|
|
58
56
|
dispatch({ type: "error", payload: error });
|
|
59
|
-
}
|
|
57
|
+
});
|
|
60
58
|
}, []);
|
|
61
59
|
return state;
|
|
62
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tfor await (const journalEntry of journal.entries) {\n\t\tconst query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n\t\tif (!query) {\n\t\t\tthrow new Error(`Missing migration: ${journalEntry.tag}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: journalEntry.breakpoints,\n\t\t\t\tfolderMillis: journalEntry.when,\n\t\t\t\thash: '',\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`Failed to parse migration: ${journalEntry.tag}`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: ExpoSQLiteDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = await readMigrationFiles(config);\n\treturn db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error };\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t};\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState };\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload };\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t};\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tfor await (const journalEntry of journal.entries) {\n\t\tconst query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n\t\tif (!query) {\n\t\t\tthrow new Error(`Missing migration: ${journalEntry.tag}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: journalEntry.breakpoints,\n\t\t\t\tfolderMillis: journalEntry.when,\n\t\t\t\thash: '',\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`Failed to parse migration: ${journalEntry.tag}`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: ExpoSQLiteDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = await readMigrationFiles(config);\n\treturn db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error };\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t};\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState };\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload };\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t};\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })\n\t\tmigrate(db, migrations as any).then(() => {\n\t\t\tdispatch({ type: 'migrated', payload: true })\n\t\t}).catch((error) => {\n\t\t\tdispatch({ type: 'error', payload: error as Error })\n\t\t});\n\t}, []);\n\n\treturn state;\n};\n"],"mappings":"AAAA,SAAS,WAAW,kBAAkB;AAWtC,eAAe,mBAAmB,EAAE,SAAS,WAAW,GAA8C;AACrG,QAAM,mBAAoC,CAAC;AAE3C,mBAAiB,gBAAgB,QAAQ,SAAS;AACjD,UAAM,QAAQ,WAAW,IAAI,aAAa,IAAI,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE;AAE3E,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM,sBAAsB,aAAa,GAAG,EAAE;AAAA,IACzD;AAEA,QAAI;AACH,YAAM,SAAS,MAAM,MAAM,0BAA0B,EAAE,IAAI,CAAC,OAAO;AAClE,eAAO;AAAA,MACR,CAAC;AAED,uBAAiB,KAAK;AAAA,QACrB,KAAK;AAAA,QACL,KAAK,aAAa;AAAA,QAClB,cAAc,aAAa;AAAA,QAC3B,MAAM;AAAA,MACP,CAAC;AAAA,IACF,QAAQ;AACP,YAAM,IAAI,MAAM,8BAA8B,aAAa,GAAG,EAAE;AAAA,IACjE;AAAA,EACD;AAEA,SAAO;AACR;AAEA,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,MAAM,mBAAmB,MAAM;AAClD,SAAO,GAAG,QAAQ,QAAQ,YAAY,GAAG,OAAO;AACjD;AAYO,MAAM,gBAAgB,CAAC,IAA6B,eAK9C;AACZ,QAAM,eAAsB;AAAA,IAC3B,SAAS;AAAA,IACT,OAAO;AAAA,EACR;AAEA,QAAM,eAAe,CAACA,QAAc,WAA0B;AAC7D,YAAQ,OAAO,MAAM;AAAA,MACpB,KAAK,aAAa;AACjB,eAAO,EAAE,GAAG,aAAa;AAAA,MAC1B;AAAA,MACA,KAAK,YAAY;AAChB,eAAO,EAAE,GAAG,cAAc,SAAS,OAAO,QAAQ;AAAA,MACnD;AAAA,MACA,KAAK,SAAS;AACb,eAAO,EAAE,GAAG,cAAc,OAAO,OAAO,QAAQ;AAAA,MACjD;AAAA,MACA,SAAS;AACR,eAAOA;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,cAAc,YAAY;AAE/D,YAAU,MAAM;AACf,aAAS,EAAE,MAAM,YAAY,CAAC;AAC9B,YAAQ,IAAI,UAAiB,EAAE,KAAK,MAAM;AACzC,eAAS,EAAE,MAAM,YAAY,SAAS,KAAK,CAAC;AAAA,IAC7C,CAAC,EAAE,MAAM,CAAC,UAAU;AACnB,eAAS,EAAE,MAAM,SAAS,SAAS,MAAe,CAAC;AAAA,IACpD,CAAC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACR;","names":["state"]}
|
package/libsql/migrator.cjs
CHANGED
|
@@ -22,9 +22,36 @@ __export(migrator_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(migrator_exports);
|
|
24
24
|
var import_migrator = require("../migrator.cjs");
|
|
25
|
-
|
|
25
|
+
var import_sql = require("../sql/sql.cjs");
|
|
26
|
+
async function migrate(db, config) {
|
|
26
27
|
const migrations = (0, import_migrator.readMigrationFiles)(config);
|
|
27
|
-
|
|
28
|
+
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
29
|
+
const migrationTableCreate = import_sql.sql`
|
|
30
|
+
CREATE TABLE IF NOT EXISTS ${import_sql.sql.identifier(migrationsTable)} (
|
|
31
|
+
id SERIAL PRIMARY KEY,
|
|
32
|
+
hash text NOT NULL,
|
|
33
|
+
created_at numeric
|
|
34
|
+
)
|
|
35
|
+
`;
|
|
36
|
+
await db.session.run(migrationTableCreate);
|
|
37
|
+
const dbMigrations = await db.values(
|
|
38
|
+
import_sql.sql`SELECT id, hash, created_at FROM ${import_sql.sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
|
|
39
|
+
);
|
|
40
|
+
const lastDbMigration = dbMigrations[0] ?? void 0;
|
|
41
|
+
const statementToBatch = [];
|
|
42
|
+
for (const migration of migrations) {
|
|
43
|
+
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
|
44
|
+
for (const stmt of migration.sql) {
|
|
45
|
+
statementToBatch.push(db.run(import_sql.sql.raw(stmt)));
|
|
46
|
+
}
|
|
47
|
+
statementToBatch.push(
|
|
48
|
+
db.run(
|
|
49
|
+
import_sql.sql`INSERT INTO ${import_sql.sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await db.session.batch(statementToBatch);
|
|
28
55
|
}
|
|
29
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
57
|
0 && (module.exports = {
|
package/libsql/migrator.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/libsql/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { LibSQLDatabase } from './driver.ts';\n\nexport function migrate<TSchema extends Record<string, unknown>>(\n\tdb: LibSQLDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\
|
|
1
|
+
{"version":3,"sources":["../../src/libsql/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport { sql } from '~/sql/sql.ts';\nimport type { LibSQLDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: LibSQLDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tconst migrationsTable = config === undefined\n\t\t? '__drizzle_migrations'\n\t\t: typeof config === 'string'\n\t\t? '__drizzle_migrations'\n\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\n\tconst migrationTableCreate = sql`\n\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\thash text NOT NULL,\n\t\t\tcreated_at numeric\n\t\t)\n\t`;\n\tawait db.session.run(migrationTableCreate);\n\n\tconst dbMigrations = await db.values<[number, string, string]>(\n\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t);\n\n\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\n\tconst statementToBatch = [];\n\n\tfor (const migration of migrations) {\n\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\tstatementToBatch.push(db.run(sql.raw(stmt)));\n\t\t\t}\n\n\t\t\tstatementToBatch.push(\n\t\t\t\tdb.run(\n\t\t\t\t\tsql`INSERT INTO ${\n\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t} (\"hash\", \"created_at\") VALUES(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tawait db.session.batch(statementToBatch);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAmC;AACnC,iBAAoB;AAGpB,eAAsB,QACrB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,QAAM,kBAAkB,WAAW,SAChC,yBACA,OAAO,WAAW,WAClB,yBACA,OAAO,mBAAmB;AAE7B,QAAM,uBAAuB;AAAA,+BACC,eAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,QAAM,GAAG,QAAQ,IAAI,oBAAoB;AAEzC,QAAM,eAAe,MAAM,GAAG;AAAA,IAC7B,kDAAuC,eAAI,WAAW,eAAe,CAAC;AAAA,EACvE;AAEA,QAAM,kBAAkB,aAAa,CAAC,KAAK;AAE3C,QAAM,mBAAmB,CAAC;AAE1B,aAAW,aAAa,YAAY;AACnC,QAAI,CAAC,mBAAmB,OAAO,gBAAgB,CAAC,CAAC,IAAK,UAAU,cAAc;AAC7E,iBAAW,QAAQ,UAAU,KAAK;AACjC,yBAAiB,KAAK,GAAG,IAAI,eAAI,IAAI,IAAI,CAAC,CAAC;AAAA,MAC5C;AAEA,uBAAiB;AAAA,QAChB,GAAG;AAAA,UACF,6BACC,eAAI,WAAW,eAAe,CAC/B,kCAAkC,UAAU,IAAI,KAAK,UAAU,YAAY;AAAA,QAC5E;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,GAAG,QAAQ,MAAM,gBAAgB;AACxC;","names":[]}
|
package/libsql/migrator.js
CHANGED
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
import { readMigrationFiles } from "../migrator.js";
|
|
2
|
-
|
|
2
|
+
import { sql } from "../sql/sql.js";
|
|
3
|
+
async function migrate(db, config) {
|
|
3
4
|
const migrations = readMigrationFiles(config);
|
|
4
|
-
|
|
5
|
+
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
6
|
+
const migrationTableCreate = sql`
|
|
7
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
8
|
+
id SERIAL PRIMARY KEY,
|
|
9
|
+
hash text NOT NULL,
|
|
10
|
+
created_at numeric
|
|
11
|
+
)
|
|
12
|
+
`;
|
|
13
|
+
await db.session.run(migrationTableCreate);
|
|
14
|
+
const dbMigrations = await db.values(
|
|
15
|
+
sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
|
|
16
|
+
);
|
|
17
|
+
const lastDbMigration = dbMigrations[0] ?? void 0;
|
|
18
|
+
const statementToBatch = [];
|
|
19
|
+
for (const migration of migrations) {
|
|
20
|
+
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
|
21
|
+
for (const stmt of migration.sql) {
|
|
22
|
+
statementToBatch.push(db.run(sql.raw(stmt)));
|
|
23
|
+
}
|
|
24
|
+
statementToBatch.push(
|
|
25
|
+
db.run(
|
|
26
|
+
sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await db.session.batch(statementToBatch);
|
|
5
32
|
}
|
|
6
33
|
export {
|
|
7
34
|
migrate
|
package/libsql/migrator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/libsql/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { LibSQLDatabase } from './driver.ts';\n\nexport function migrate<TSchema extends Record<string, unknown>>(\n\tdb: LibSQLDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\
|
|
1
|
+
{"version":3,"sources":["../../src/libsql/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport { sql } from '~/sql/sql.ts';\nimport type { LibSQLDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: LibSQLDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tconst migrationsTable = config === undefined\n\t\t? '__drizzle_migrations'\n\t\t: typeof config === 'string'\n\t\t? '__drizzle_migrations'\n\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\n\tconst migrationTableCreate = sql`\n\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\thash text NOT NULL,\n\t\t\tcreated_at numeric\n\t\t)\n\t`;\n\tawait db.session.run(migrationTableCreate);\n\n\tconst dbMigrations = await db.values<[number, string, string]>(\n\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t);\n\n\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\n\tconst statementToBatch = [];\n\n\tfor (const migration of migrations) {\n\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\tstatementToBatch.push(db.run(sql.raw(stmt)));\n\t\t\t}\n\n\t\t\tstatementToBatch.push(\n\t\t\t\tdb.run(\n\t\t\t\t\tsql`INSERT INTO ${\n\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t} (\"hash\", \"created_at\") VALUES(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tawait db.session.batch(statementToBatch);\n}\n"],"mappings":"AACA,SAAS,0BAA0B;AACnC,SAAS,WAAW;AAGpB,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,QAAM,kBAAkB,WAAW,SAChC,yBACA,OAAO,WAAW,WAClB,yBACA,OAAO,mBAAmB;AAE7B,QAAM,uBAAuB;AAAA,+BACC,IAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,QAAM,GAAG,QAAQ,IAAI,oBAAoB;AAEzC,QAAM,eAAe,MAAM,GAAG;AAAA,IAC7B,uCAAuC,IAAI,WAAW,eAAe,CAAC;AAAA,EACvE;AAEA,QAAM,kBAAkB,aAAa,CAAC,KAAK;AAE3C,QAAM,mBAAmB,CAAC;AAE1B,aAAW,aAAa,YAAY;AACnC,QAAI,CAAC,mBAAmB,OAAO,gBAAgB,CAAC,CAAC,IAAK,UAAU,cAAc;AAC7E,iBAAW,QAAQ,UAAU,KAAK;AACjC,yBAAiB,KAAK,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;AAAA,MAC5C;AAEA,uBAAiB;AAAA,QAChB,GAAG;AAAA,UACF,kBACC,IAAI,WAAW,eAAe,CAC/B,kCAAkC,UAAU,IAAI,KAAK,UAAU,YAAY;AAAA,QAC5E;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,GAAG,QAAQ,MAAM,gBAAgB;AACxC;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var driver_exports = {};
|
|
20
|
+
__export(driver_exports, {
|
|
21
|
+
drizzle: () => drizzle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(driver_exports);
|
|
24
|
+
var import_logger = require("../logger.cjs");
|
|
25
|
+
var import_relations = require("../relations.cjs");
|
|
26
|
+
var import_db = require("../sqlite-core/db.cjs");
|
|
27
|
+
var import_dialect = require("../sqlite-core/dialect.cjs");
|
|
28
|
+
var import_session = require("./session.cjs");
|
|
29
|
+
function drizzle(client, config = {}) {
|
|
30
|
+
const dialect = new import_dialect.SQLiteAsyncDialect();
|
|
31
|
+
let logger;
|
|
32
|
+
if (config.logger === true) {
|
|
33
|
+
logger = new import_logger.DefaultLogger();
|
|
34
|
+
} else if (config.logger !== false) {
|
|
35
|
+
logger = config.logger;
|
|
36
|
+
}
|
|
37
|
+
let schema;
|
|
38
|
+
if (config.schema) {
|
|
39
|
+
const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(
|
|
40
|
+
config.schema,
|
|
41
|
+
import_relations.createTableRelationsHelpers
|
|
42
|
+
);
|
|
43
|
+
schema = {
|
|
44
|
+
fullSchema: config.schema,
|
|
45
|
+
schema: tablesConfig.tables,
|
|
46
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const session = new import_session.OPSQLiteSession(client, dialect, schema, { logger });
|
|
50
|
+
return new import_db.BaseSQLiteDatabase("async", dialect, session, schema);
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
drizzle
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=driver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/driver.ts"],"sourcesContent":["import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';\nimport { DefaultLogger } from '~/logger.ts';\nimport {\n createTableRelationsHelpers,\n extractTablesRelationalConfig,\n type RelationalSchemaConfig,\n type TablesRelationalConfig,\n} from '~/relations.ts';\nimport { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';\nimport { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleConfig } from '~/utils.ts';\nimport { OPSQLiteSession } from './session.ts';\n\nexport type OPSQLiteDatabase<\n TSchema extends Record<string, unknown> = Record<string, never>,\n> = BaseSQLiteDatabase<'async', QueryResult, TSchema>;\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n client: OPSQLiteConnection,\n config: DrizzleConfig<TSchema> = {},\n): OPSQLiteDatabase<TSchema> {\n const dialect = new SQLiteAsyncDialect();\n let logger;\n if (config.logger === true) {\n logger = new DefaultLogger();\n } else if (config.logger !== false) {\n logger = config.logger;\n }\n\n let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n if (config.schema) {\n const tablesConfig = extractTablesRelationalConfig(\n config.schema,\n createTableRelationsHelpers,\n );\n schema = {\n fullSchema: config.schema,\n schema: tablesConfig.tables,\n tableNamesMap: tablesConfig.tableNamesMap,\n };\n }\n\n const session = new OPSQLiteSession(client, dialect, schema, { logger });\n return new BaseSQLiteDatabase('async', dialect, session, schema) as OPSQLiteDatabase<TSchema>;\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,uBAKO;AACP,gBAAmC;AACnC,qBAAmC;AAEnC,qBAAgC;AAMzB,SAAS,QACZ,QACA,SAAiC,CAAC,GACT;AACzB,QAAM,UAAU,IAAI,kCAAmB;AACvC,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AACxB,aAAS,IAAI,4BAAc;AAAA,EAC/B,WAAW,OAAO,WAAW,OAAO;AAChC,aAAS,OAAO;AAAA,EACpB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AACf,UAAM,mBAAe;AAAA,MACjB,OAAO;AAAA,MACP;AAAA,IACJ;AACA,aAAS;AAAA,MACL,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAChC;AAAA,EACJ;AAEA,QAAM,UAAU,IAAI,+BAAgB,QAAQ,SAAS,QAAQ,EAAE,OAAO,CAAC;AACvE,SAAO,IAAI,6BAAmB,SAAS,SAAS,SAAS,MAAM;AACnE;","names":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { BaseSQLiteDatabase } from "../sqlite-core/db.cjs";
|
|
3
|
+
import type { DrizzleConfig } from "../utils.cjs";
|
|
4
|
+
export type OPSQLiteDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = BaseSQLiteDatabase<'async', QueryResult, TSchema>;
|
|
5
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: OPSQLiteConnection, config?: DrizzleConfig<TSchema>): OPSQLiteDatabase<TSchema>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { BaseSQLiteDatabase } from "../sqlite-core/db.js";
|
|
3
|
+
import type { DrizzleConfig } from "../utils.js";
|
|
4
|
+
export type OPSQLiteDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = BaseSQLiteDatabase<'async', QueryResult, TSchema>;
|
|
5
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: OPSQLiteConnection, config?: DrizzleConfig<TSchema>): OPSQLiteDatabase<TSchema>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DefaultLogger } from "../logger.js";
|
|
2
|
+
import {
|
|
3
|
+
createTableRelationsHelpers,
|
|
4
|
+
extractTablesRelationalConfig
|
|
5
|
+
} from "../relations.js";
|
|
6
|
+
import { BaseSQLiteDatabase } from "../sqlite-core/db.js";
|
|
7
|
+
import { SQLiteAsyncDialect } from "../sqlite-core/dialect.js";
|
|
8
|
+
import { OPSQLiteSession } from "./session.js";
|
|
9
|
+
function drizzle(client, config = {}) {
|
|
10
|
+
const dialect = new SQLiteAsyncDialect();
|
|
11
|
+
let logger;
|
|
12
|
+
if (config.logger === true) {
|
|
13
|
+
logger = new DefaultLogger();
|
|
14
|
+
} else if (config.logger !== false) {
|
|
15
|
+
logger = config.logger;
|
|
16
|
+
}
|
|
17
|
+
let schema;
|
|
18
|
+
if (config.schema) {
|
|
19
|
+
const tablesConfig = extractTablesRelationalConfig(
|
|
20
|
+
config.schema,
|
|
21
|
+
createTableRelationsHelpers
|
|
22
|
+
);
|
|
23
|
+
schema = {
|
|
24
|
+
fullSchema: config.schema,
|
|
25
|
+
schema: tablesConfig.tables,
|
|
26
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const session = new OPSQLiteSession(client, dialect, schema, { logger });
|
|
30
|
+
return new BaseSQLiteDatabase("async", dialect, session, schema);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
drizzle
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/driver.ts"],"sourcesContent":["import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';\nimport { DefaultLogger } from '~/logger.ts';\nimport {\n createTableRelationsHelpers,\n extractTablesRelationalConfig,\n type RelationalSchemaConfig,\n type TablesRelationalConfig,\n} from '~/relations.ts';\nimport { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';\nimport { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleConfig } from '~/utils.ts';\nimport { OPSQLiteSession } from './session.ts';\n\nexport type OPSQLiteDatabase<\n TSchema extends Record<string, unknown> = Record<string, never>,\n> = BaseSQLiteDatabase<'async', QueryResult, TSchema>;\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n client: OPSQLiteConnection,\n config: DrizzleConfig<TSchema> = {},\n): OPSQLiteDatabase<TSchema> {\n const dialect = new SQLiteAsyncDialect();\n let logger;\n if (config.logger === true) {\n logger = new DefaultLogger();\n } else if (config.logger !== false) {\n logger = config.logger;\n }\n\n let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n if (config.schema) {\n const tablesConfig = extractTablesRelationalConfig(\n config.schema,\n createTableRelationsHelpers,\n );\n schema = {\n fullSchema: config.schema,\n schema: tablesConfig.tables,\n tableNamesMap: tablesConfig.tableNamesMap,\n };\n }\n\n const session = new OPSQLiteSession(client, dialect, schema, { logger });\n return new BaseSQLiteDatabase('async', dialect, session, schema) as OPSQLiteDatabase<TSchema>;\n}"],"mappings":"AACA,SAAS,qBAAqB;AAC9B;AAAA,EACI;AAAA,EACA;AAAA,OAGG;AACP,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAEnC,SAAS,uBAAuB;AAMzB,SAAS,QACZ,QACA,SAAiC,CAAC,GACT;AACzB,QAAM,UAAU,IAAI,mBAAmB;AACvC,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AACxB,aAAS,IAAI,cAAc;AAAA,EAC/B,WAAW,OAAO,WAAW,OAAO;AAChC,aAAS,OAAO;AAAA,EACpB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AACf,UAAM,eAAe;AAAA,MACjB,OAAO;AAAA,MACP;AAAA,IACJ;AACA,aAAS;AAAA,MACL,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAChC;AAAA,EACJ;AAEA,QAAM,UAAU,IAAI,gBAAgB,QAAQ,SAAS,QAAQ,EAAE,OAAO,CAAC;AACvE,SAAO,IAAI,mBAAmB,SAAS,SAAS,SAAS,MAAM;AACnE;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var op_sqlite_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(op_sqlite_exports);
|
|
18
|
+
__reExport(op_sqlite_exports, require("./driver.cjs"), module.exports);
|
|
19
|
+
__reExport(op_sqlite_exports, require("./session.cjs"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./driver.cjs"),
|
|
23
|
+
...require("./session.cjs")
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,wBAAd;AACA,8BAAc,yBADd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var migrator_exports = {};
|
|
20
|
+
__export(migrator_exports, {
|
|
21
|
+
migrate: () => migrate,
|
|
22
|
+
useMigrations: () => useMigrations
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(migrator_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
async function readMigrationFiles({ journal, migrations }) {
|
|
27
|
+
const migrationQueries = [];
|
|
28
|
+
for await (const journalEntry of journal.entries) {
|
|
29
|
+
const query = migrations[`m${journalEntry.idx.toString().padStart(4, "0")}`];
|
|
30
|
+
if (!query) {
|
|
31
|
+
throw new Error(`Missing migration: ${journalEntry.tag}`);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
35
|
+
return it;
|
|
36
|
+
});
|
|
37
|
+
migrationQueries.push({
|
|
38
|
+
sql: result,
|
|
39
|
+
bps: journalEntry.breakpoints,
|
|
40
|
+
folderMillis: journalEntry.when,
|
|
41
|
+
hash: ""
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error(`Failed to parse migration: ${journalEntry.tag}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return migrationQueries;
|
|
48
|
+
}
|
|
49
|
+
async function migrate(db, config) {
|
|
50
|
+
const migrations = await readMigrationFiles(config);
|
|
51
|
+
return db.dialect.migrate(migrations, db.session);
|
|
52
|
+
}
|
|
53
|
+
const useMigrations = (db, migrations) => {
|
|
54
|
+
const initialState = {
|
|
55
|
+
success: false,
|
|
56
|
+
error: void 0
|
|
57
|
+
};
|
|
58
|
+
const fetchReducer = (state2, action) => {
|
|
59
|
+
switch (action.type) {
|
|
60
|
+
case "migrating": {
|
|
61
|
+
return { ...initialState };
|
|
62
|
+
}
|
|
63
|
+
case "migrated": {
|
|
64
|
+
return { ...initialState, success: action.payload };
|
|
65
|
+
}
|
|
66
|
+
case "error": {
|
|
67
|
+
return { ...initialState, error: action.payload };
|
|
68
|
+
}
|
|
69
|
+
default: {
|
|
70
|
+
return state2;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const [state, dispatch] = (0, import_react.useReducer)(fetchReducer, initialState);
|
|
75
|
+
(0, import_react.useEffect)(() => {
|
|
76
|
+
dispatch({ type: "migrating" });
|
|
77
|
+
migrate(db, migrations).then(() => {
|
|
78
|
+
dispatch({ type: "migrated", payload: true });
|
|
79
|
+
}).catch((error) => {
|
|
80
|
+
dispatch({ type: "error", payload: error });
|
|
81
|
+
});
|
|
82
|
+
}, []);
|
|
83
|
+
return state;
|
|
84
|
+
};
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
migrate,
|
|
88
|
+
useMigrations
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=migrator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from \"react\";\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { OPSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n journal: {\n entries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n };\n migrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n const migrationQueries: MigrationMeta[] = [];\n\n for await (const journalEntry of journal.entries) {\n const query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n if (!query) {\n throw new Error(`Missing migration: ${journalEntry.tag}`);\n }\n\n try {\n const result = query.split('--> statement-breakpoint').map((it) => {\n return it;\n });\n\n migrationQueries.push({\n sql: result,\n bps: journalEntry.breakpoints,\n folderMillis: journalEntry.when,\n hash: '',\n });\n } catch {\n throw new Error(`Failed to parse migration: ${journalEntry.tag}`);\n }\n }\n\n return migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n db: OPSQLiteDatabase<TSchema>,\n config: MigrationConfig,\n) {\n const migrations = await readMigrationFiles(config);\n return db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error }\n\nexport const useMigrations = (db: OPSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t}\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState }\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload }\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state\n\t\t\t}\n\t\t}\n\t}\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })\n\t\tmigrate(db, migrations).then(() => {\n\t\t\tdispatch({ type: 'migrated', payload: true })\n\t\t}).catch((error) => {\n\t\t\tdispatch({ type: 'error', payload: error as Error })\n\t\t});\n\t}, []);\n\n\treturn state;\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AAWtC,eAAe,mBAAmB,EAAE,SAAS,WAAW,GAA8C;AAClG,QAAM,mBAAoC,CAAC;AAE3C,mBAAiB,gBAAgB,QAAQ,SAAS;AAC9C,UAAM,QAAQ,WAAW,IAAI,aAAa,IAAI,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE;AAE3E,QAAI,CAAC,OAAO;AACR,YAAM,IAAI,MAAM,sBAAsB,aAAa,GAAG,EAAE;AAAA,IAC5D;AAEA,QAAI;AACA,YAAM,SAAS,MAAM,MAAM,0BAA0B,EAAE,IAAI,CAAC,OAAO;AAC/D,eAAO;AAAA,MACX,CAAC;AAED,uBAAiB,KAAK;AAAA,QAClB,KAAK;AAAA,QACL,KAAK,aAAa;AAAA,QAClB,cAAc,aAAa;AAAA,QAC3B,MAAM;AAAA,MACV,CAAC;AAAA,IACL,QAAQ;AACJ,YAAM,IAAI,MAAM,8BAA8B,aAAa,GAAG,EAAE;AAAA,IACpE;AAAA,EACJ;AAEA,SAAO;AACX;AAEA,eAAsB,QAClB,IACA,QACF;AACE,QAAM,aAAa,MAAM,mBAAmB,MAAM;AAClD,SAAO,GAAG,QAAQ,QAAQ,YAAY,GAAG,OAAO;AACpD;AAYO,MAAM,gBAAgB,CAAC,IAA2B,eAK5C;AACZ,QAAM,eAAsB;AAAA,IAC3B,SAAS;AAAA,IACT,OAAO;AAAA,EACR;AAEA,QAAM,eAAe,CAACA,QAAc,WAA0B;AAC7D,YAAQ,OAAO,MAAM;AAAA,MACpB,KAAK,aAAa;AACjB,eAAO,EAAE,GAAG,aAAa;AAAA,MAC1B;AAAA,MACA,KAAK,YAAY;AAChB,eAAO,EAAE,GAAG,cAAc,SAAS,OAAO,QAAQ;AAAA,MACnD;AAAA,MACA,KAAK,SAAS;AACb,eAAO,EAAE,GAAG,cAAc,OAAO,OAAO,QAAQ;AAAA,MACjD;AAAA,MACA,SAAS;AACR,eAAOA;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAW,cAAc,YAAY;AAE/D,8BAAU,MAAM;AACf,aAAS,EAAE,MAAM,YAAY,CAAC;AAC9B,YAAQ,IAAI,UAAU,EAAE,KAAK,MAAM;AAClC,eAAS,EAAE,MAAM,YAAY,SAAS,KAAK,CAAC;AAAA,IAC7C,CAAC,EAAE,MAAM,CAAC,UAAU;AACnB,eAAS,EAAE,MAAM,SAAS,SAAS,MAAe,CAAC;AAAA,IACpD,CAAC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACR;","names":["state"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OPSQLiteDatabase } from "./driver.cjs";
|
|
2
|
+
interface MigrationConfig {
|
|
3
|
+
journal: {
|
|
4
|
+
entries: {
|
|
5
|
+
idx: number;
|
|
6
|
+
when: number;
|
|
7
|
+
tag: string;
|
|
8
|
+
breakpoints: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
migrations: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function migrate<TSchema extends Record<string, unknown>>(db: OPSQLiteDatabase<TSchema>, config: MigrationConfig): Promise<void>;
|
|
14
|
+
interface State {
|
|
15
|
+
success: boolean;
|
|
16
|
+
error?: Error;
|
|
17
|
+
}
|
|
18
|
+
export declare const useMigrations: (db: OPSQLiteDatabase<any>, migrations: {
|
|
19
|
+
journal: {
|
|
20
|
+
entries: {
|
|
21
|
+
idx: number;
|
|
22
|
+
when: number;
|
|
23
|
+
tag: string;
|
|
24
|
+
breakpoints: boolean;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
migrations: Record<string, string>;
|
|
28
|
+
}) => State;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OPSQLiteDatabase } from "./driver.js";
|
|
2
|
+
interface MigrationConfig {
|
|
3
|
+
journal: {
|
|
4
|
+
entries: {
|
|
5
|
+
idx: number;
|
|
6
|
+
when: number;
|
|
7
|
+
tag: string;
|
|
8
|
+
breakpoints: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
migrations: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function migrate<TSchema extends Record<string, unknown>>(db: OPSQLiteDatabase<TSchema>, config: MigrationConfig): Promise<void>;
|
|
14
|
+
interface State {
|
|
15
|
+
success: boolean;
|
|
16
|
+
error?: Error;
|
|
17
|
+
}
|
|
18
|
+
export declare const useMigrations: (db: OPSQLiteDatabase<any>, migrations: {
|
|
19
|
+
journal: {
|
|
20
|
+
entries: {
|
|
21
|
+
idx: number;
|
|
22
|
+
when: number;
|
|
23
|
+
tag: string;
|
|
24
|
+
breakpoints: boolean;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
migrations: Record<string, string>;
|
|
28
|
+
}) => State;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useEffect, useReducer } from "react";
|
|
2
|
+
async function readMigrationFiles({ journal, migrations }) {
|
|
3
|
+
const migrationQueries = [];
|
|
4
|
+
for await (const journalEntry of journal.entries) {
|
|
5
|
+
const query = migrations[`m${journalEntry.idx.toString().padStart(4, "0")}`];
|
|
6
|
+
if (!query) {
|
|
7
|
+
throw new Error(`Missing migration: ${journalEntry.tag}`);
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
11
|
+
return it;
|
|
12
|
+
});
|
|
13
|
+
migrationQueries.push({
|
|
14
|
+
sql: result,
|
|
15
|
+
bps: journalEntry.breakpoints,
|
|
16
|
+
folderMillis: journalEntry.when,
|
|
17
|
+
hash: ""
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error(`Failed to parse migration: ${journalEntry.tag}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return migrationQueries;
|
|
24
|
+
}
|
|
25
|
+
async function migrate(db, config) {
|
|
26
|
+
const migrations = await readMigrationFiles(config);
|
|
27
|
+
return db.dialect.migrate(migrations, db.session);
|
|
28
|
+
}
|
|
29
|
+
const useMigrations = (db, migrations) => {
|
|
30
|
+
const initialState = {
|
|
31
|
+
success: false,
|
|
32
|
+
error: void 0
|
|
33
|
+
};
|
|
34
|
+
const fetchReducer = (state2, action) => {
|
|
35
|
+
switch (action.type) {
|
|
36
|
+
case "migrating": {
|
|
37
|
+
return { ...initialState };
|
|
38
|
+
}
|
|
39
|
+
case "migrated": {
|
|
40
|
+
return { ...initialState, success: action.payload };
|
|
41
|
+
}
|
|
42
|
+
case "error": {
|
|
43
|
+
return { ...initialState, error: action.payload };
|
|
44
|
+
}
|
|
45
|
+
default: {
|
|
46
|
+
return state2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const [state, dispatch] = useReducer(fetchReducer, initialState);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
dispatch({ type: "migrating" });
|
|
53
|
+
migrate(db, migrations).then(() => {
|
|
54
|
+
dispatch({ type: "migrated", payload: true });
|
|
55
|
+
}).catch((error) => {
|
|
56
|
+
dispatch({ type: "error", payload: error });
|
|
57
|
+
});
|
|
58
|
+
}, []);
|
|
59
|
+
return state;
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
migrate,
|
|
63
|
+
useMigrations
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from \"react\";\nimport type { MigrationMeta } from '~/migrator.ts';\nimport type { OPSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n journal: {\n entries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n };\n migrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n const migrationQueries: MigrationMeta[] = [];\n\n for await (const journalEntry of journal.entries) {\n const query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];\n\n if (!query) {\n throw new Error(`Missing migration: ${journalEntry.tag}`);\n }\n\n try {\n const result = query.split('--> statement-breakpoint').map((it) => {\n return it;\n });\n\n migrationQueries.push({\n sql: result,\n bps: journalEntry.breakpoints,\n folderMillis: journalEntry.when,\n hash: '',\n });\n } catch {\n throw new Error(`Failed to parse migration: ${journalEntry.tag}`);\n }\n }\n\n return migrationQueries;\n}\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n db: OPSQLiteDatabase<TSchema>,\n config: MigrationConfig,\n) {\n const migrations = await readMigrationFiles(config);\n return db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error }\n\nexport const useMigrations = (db: OPSQLiteDatabase<any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t}\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState }\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload }\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload }\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state\n\t\t\t}\n\t\t}\n\t}\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' })\n\t\tmigrate(db, migrations).then(() => {\n\t\t\tdispatch({ type: 'migrated', payload: true })\n\t\t}).catch((error) => {\n\t\t\tdispatch({ type: 'error', payload: error as Error })\n\t\t});\n\t}, []);\n\n\treturn state;\n}"],"mappings":"AAAA,SAAS,WAAW,kBAAkB;AAWtC,eAAe,mBAAmB,EAAE,SAAS,WAAW,GAA8C;AAClG,QAAM,mBAAoC,CAAC;AAE3C,mBAAiB,gBAAgB,QAAQ,SAAS;AAC9C,UAAM,QAAQ,WAAW,IAAI,aAAa,IAAI,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE;AAE3E,QAAI,CAAC,OAAO;AACR,YAAM,IAAI,MAAM,sBAAsB,aAAa,GAAG,EAAE;AAAA,IAC5D;AAEA,QAAI;AACA,YAAM,SAAS,MAAM,MAAM,0BAA0B,EAAE,IAAI,CAAC,OAAO;AAC/D,eAAO;AAAA,MACX,CAAC;AAED,uBAAiB,KAAK;AAAA,QAClB,KAAK;AAAA,QACL,KAAK,aAAa;AAAA,QAClB,cAAc,aAAa;AAAA,QAC3B,MAAM;AAAA,MACV,CAAC;AAAA,IACL,QAAQ;AACJ,YAAM,IAAI,MAAM,8BAA8B,aAAa,GAAG,EAAE;AAAA,IACpE;AAAA,EACJ;AAEA,SAAO;AACX;AAEA,eAAsB,QAClB,IACA,QACF;AACE,QAAM,aAAa,MAAM,mBAAmB,MAAM;AAClD,SAAO,GAAG,QAAQ,QAAQ,YAAY,GAAG,OAAO;AACpD;AAYO,MAAM,gBAAgB,CAAC,IAA2B,eAK5C;AACZ,QAAM,eAAsB;AAAA,IAC3B,SAAS;AAAA,IACT,OAAO;AAAA,EACR;AAEA,QAAM,eAAe,CAACA,QAAc,WAA0B;AAC7D,YAAQ,OAAO,MAAM;AAAA,MACpB,KAAK,aAAa;AACjB,eAAO,EAAE,GAAG,aAAa;AAAA,MAC1B;AAAA,MACA,KAAK,YAAY;AAChB,eAAO,EAAE,GAAG,cAAc,SAAS,OAAO,QAAQ;AAAA,MACnD;AAAA,MACA,KAAK,SAAS;AACb,eAAO,EAAE,GAAG,cAAc,OAAO,OAAO,QAAQ;AAAA,MACjD;AAAA,MACA,SAAS;AACR,eAAOA;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,cAAc,YAAY;AAE/D,YAAU,MAAM;AACf,aAAS,EAAE,MAAM,YAAY,CAAC;AAC9B,YAAQ,IAAI,UAAU,EAAE,KAAK,MAAM;AAClC,eAAS,EAAE,MAAM,YAAY,SAAS,KAAK,CAAC;AAAA,IAC7C,CAAC,EAAE,MAAM,CAAC,UAAU;AACnB,eAAS,EAAE,MAAM,SAAS,SAAS,MAAe,CAAC;AAAA,IACpD,CAAC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACR;","names":["state"]}
|