feat(db): use wa-sqlite
This commit is contained in:
parent
877fd5a806
commit
36ff7afa4a
14 changed files with 232 additions and 177 deletions
48
src/lib/kysely-wasqlite-worker/index.ts
Normal file
48
src/lib/kysely-wasqlite-worker/index.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import type { DatabaseIntrospector, Dialect, DialectAdapter, Driver, Kysely, QueryCompiler } from "kysely";
|
||||
import type { WaSqliteWorkerDialectConfig } from "./type";
|
||||
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from "kysely";
|
||||
import { WaSqliteWorkerDriver } from "./driver";
|
||||
|
||||
export type { Promisable, WaSqliteWorkerDialectConfig } from "./type";
|
||||
export { createOnMessageCallback } from "./worker/utils";
|
||||
|
||||
export {
|
||||
customFunction,
|
||||
isIdbSupported,
|
||||
isModuleWorkerSupport,
|
||||
isOpfsSupported,
|
||||
type SQLiteDB,
|
||||
} from "@subframe7536/sqlite-wasm";
|
||||
|
||||
export class WaSqliteWorkerDialect implements Dialect {
|
||||
/**
|
||||
* dialect for [`wa-sqlite`](https://github.com/rhashimoto/wa-sqlite),
|
||||
* execute sql in `Web Worker`,
|
||||
* store data in [OPFS](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system) or IndexedDB
|
||||
*
|
||||
* @example
|
||||
* import { WaSqliteWorkerDialect } from 'kysely-wasqlite-worker'
|
||||
*
|
||||
* const dialect = new WaSqliteWorkerDialect({
|
||||
* fileName: 'test',
|
||||
* })
|
||||
*/
|
||||
constructor(private config: WaSqliteWorkerDialectConfig) {}
|
||||
|
||||
createDriver(): Driver {
|
||||
return new WaSqliteWorkerDriver(this.config);
|
||||
}
|
||||
|
||||
createQueryCompiler(): QueryCompiler {
|
||||
return new SqliteQueryCompiler();
|
||||
}
|
||||
|
||||
createAdapter(): DialectAdapter {
|
||||
return new SqliteAdapter();
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
createIntrospector(db: Kysely<any>): DatabaseIntrospector {
|
||||
return new SqliteIntrospector(db);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue