um-react/src/util/sqlite.ts
Jixun Wu da39d5f5c1
All checks were successful
continuous-integration/drone/push Build is passing
feat: import ekey from Android db (#20)
2023-06-11 16:22:57 +01:00

16 lines
490 B
TypeScript

import * as initSqlite from 'sql.js';
const urlWasm = new URL('@nm/sql.js/dist/sql-wasm.wasm', import.meta.url).toString();
export type SQLStatic = Awaited<ReturnType<(typeof initSqlite)['default']>>;
export type SQLDatabase = SQLStatic['Database']['prototype'];
let sqlLoaderPromise: Promise<SQLStatic> | void;
export async function loadSQL() {
if (!sqlLoaderPromise) {
sqlLoaderPromise = initSqlite.default({ locateFile: () => urlWasm });
}
return await sqlLoaderPromise;
}