Skip to content

Commit bf443c3

Browse files
committed
docs: add uils
1 parent 6c00b00 commit bf443c3

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,111 @@ const buf = await exportDatabase(core.vfs, core.path)
237237
await close(core)
238238
```
239239

240+
### Utils
241+
242+
```ts
243+
function dumpVFS(vfs: FacadeVFS, path: string, onDone?: (vfs: FacadeVFS, path: string) => any): ReadableStream
244+
245+
function exportDatabaseFromIDB(vfs: FacadeVFS, path: string): Promise<Uint8Array>
246+
247+
function exportDatabaseFromFsHandle(vfs: FacadeVFS, path: string): Promise<Uint8Array>
248+
249+
/**
250+
* Export database to `Uint8Array`
251+
* @param vfs SQLite VFS
252+
* @param path database path
253+
*/
254+
function exportDatabase(vfs: FacadeVFS, path: string): Promise<Uint8Array>
255+
256+
function importDatabaseToIdb(vfs: FacadeVFS, path: string, stream: ReadableStream<Uint8Array>): Promise<void>
257+
258+
/**
259+
* Import database from `File` or `ReadableStream`
260+
* @param vfs SQLite VFS
261+
* @param path db path
262+
* @param data existing database
263+
*/
264+
function importDatabase(vfs: FacadeVFS, path: string, data: File | ReadableStream<Uint8Array>): Promise<void>
265+
266+
/**
267+
* check if IndexedDB and Web Locks API supported
268+
*/
269+
function isIdbSupported(): boolean
270+
271+
/**
272+
* check if [OPFS SyncAccessHandle](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle) supported
273+
*/
274+
function isOpfsSupported(): Promise<boolean>
275+
276+
/**
277+
* check `new Worker(url, { type: 'module' })` support
278+
*
279+
* {@link https://stackoverflow.com/questions/62954570/javascript-feature-detect-module-support-for-web-workers Reference}
280+
*/
281+
function isModuleWorkerSupport(): boolean
282+
283+
/**
284+
* Create custom function, run js script in SQLite
285+
*
286+
* @example
287+
* ```ts
288+
* import { customFunction, initSQLite, isOpfsSupported } from '@subframe7536/sqlite-wasm'
289+
* import { useOpfsStorage } from '@subframe7536/sqlite-wasm/opfs'
290+
* import { uuidv7 } from 'uuidv7'
291+
*
292+
* const { run, sqlite, db } = await initSQLite(
293+
* useOpfsStorage('test')
294+
* )
295+
* customFunction(sqlite, db, 'uuidv7', () => uuidv7())
296+
* console.log(await run('select uuidv7() as a'))
297+
* // [{ "a": "01932f1b-b663-7714-af4d-17a3d9efc7b3" }]
298+
* ```
299+
*/
300+
function customFunction<N extends string, T extends SQLiteCompatibleType[]>(sqlite: SQLiteAPI, db: number, fnName: N, fn: N extends '' ? never : (...args: T) => (SQLiteCompatibleType | number[]) | null, options?: {
301+
deterministic?: boolean
302+
directOnly?: boolean
303+
varargs?: boolean
304+
}): void
305+
306+
function customFunctionCore<N extends string, T extends SQLiteCompatibleType[]>(core: SQLiteDBCore, fnName: N, fn: N extends '' ? never : (...args: T) => (SQLiteCompatibleType | number[]) | null, options?: {
307+
deterministic?: boolean
308+
directOnly?: boolean
309+
varargs?: boolean
310+
}): void
311+
312+
/**
313+
* Parse options with existing database
314+
* @param data database File or ReadableStream
315+
* @param options extra options
316+
* @example
317+
* ```ts
318+
* import { initSQLite, withExistDB } from '@subframe7536/sqlite-wasm'
319+
* import { useIdbStorage } from '@subframe7536/sqlite-wasm/idb'
320+
*
321+
* const db = initSQLite(
322+
* useIdbStorage('test.db', withExistDB(FileOrReadableStream, { url }))
323+
* )
324+
* ```
325+
*/
326+
function withExistDB<T extends BaseStorageOptions>(data: File | ReadableStream, options?: Omit<T, 'beforeOpen'>): T
327+
328+
function close(core: SQLiteDBCore): Promise<void>
329+
330+
function changes(core: SQLiteDBCore): number | bigint
331+
332+
function lastInsertRowId(core: SQLiteDBCore): number | bigint
333+
334+
function stream(core: SQLiteDBCore, onData: (data: Record<string, SQLiteCompatibleType>) => void, sql: string, parameters?: SQLiteCompatibleType[]): Promise<void>
335+
336+
function run(core: SQLiteDBCore, sql: string, parameters?: SQLiteCompatibleType[]): Promise<Array<Record<string, SQLiteCompatibleType>>>
337+
338+
function iterator(core: SQLiteDBCore, sql: string, parameters?: SQLiteCompatibleType[], chunkSize?: number): AsyncIterableIterator<Record<string, SQLiteCompatibleType>[]>
339+
340+
function parseOpenV2Flag(readonly?: boolean): number
341+
342+
function reopen(core: SQLiteDBCore, readonly?: boolean): Promise<void>
343+
```
344+
240345
## License
241346

242347
MIT

0 commit comments

Comments
 (0)