@@ -15,11 +15,10 @@ import { initSQLite, isOpfsSupported, useMemoryStorage } from '@subframe7536/sql
1515
1616// optional url
1717const url = ' https://cdn.jsdelivr.net/npm/@subframe7536/sqlite-wasm@0.5.0/wa-sqlite.wasm'
18- const url1 = ' https://cdn.jsdelivr.net/gh/subframe7536/sqlite-wasm@v0.5.0/wa-sqlite-fts5/wa-sqlite.wasm'
18+ const url1 =
19+ ' https://cdn.jsdelivr.net/gh/subframe7536/sqlite-wasm@v0.5.0/wa-sqlite-fts5/wa-sqlite.wasm'
1920
20- const { run, changes, lastInsertRowId, close } = await initSQLite (
21- useMemoryStorage ({ url })
22- )
21+ const { run, changes, lastInsertRowId, close } = await initSQLite (useMemoryStorage ({ url }))
2322```
2423
2524### IndexedDB
@@ -34,11 +33,10 @@ import { useIdbStorage } from '@subframe7536/sqlite-wasm/idb'
3433
3534// optional url
3635const url = ' https://cdn.jsdelivr.net/npm/@subframe7536/sqlite-wasm@0.5.0/wa-sqlite-async.wasm'
37- const url1 = ' https://cdn.jsdelivr.net/gh/subframe7536/sqlite-wasm@v0.5.0/wa-sqlite-fts5/wa-sqlite-async.wasm'
36+ const url1 =
37+ ' https://cdn.jsdelivr.net/gh/subframe7536/sqlite-wasm@v0.5.0/wa-sqlite-fts5/wa-sqlite-async.wasm'
3838
39- const { run, changes, lastInsertRowId, close } = await initSQLite (
40- useIdbStorage (' test.db' , { url })
41- )
39+ const { run, changes, lastInsertRowId, close } = await initSQLite (useIdbStorage (' test.db' , { url }))
4240```
4341
4442#### IdbMemory
@@ -55,7 +53,7 @@ import { useIdbMemoryStorage } from '@subframe7536/sqlite-wasm/idb-memory'
5553const url = ' https://cdn.jsdelivr.net/npm/@subframe7536/sqlite-wasm@0.5.0/dist/wa-sqlite-async.wasm'
5654
5755const { run, changes, lastInsertRowId, close } = await initSQLite (
58- useIdbMemoryStorage (' test.db' , { url })
56+ useIdbMemoryStorage (' test.db' , { url }),
5957)
6058```
6159
@@ -76,12 +74,11 @@ import { useOpfsStorage } from '@subframe7536/sqlite-wasm/opfs'
7674const url = ' https://cdn.jsdelivr.net/npm/@subframe7536/sqlite-wasm@0.5.0/dist/wa-sqlite.wasm'
7775
7876onmessage = async () => {
79- if (! await isOpfsSupported ()) { // this can be called in main thread
77+ if (! (await isOpfsSupported ())) {
78+ // this can be called in main thread
8079 return
8180 }
82- const { run, changes, lastInsertRowId, close } = await initSQLite (
83- useOpfsStorage (' test.db' , url )
84- )
81+ const { run, changes, lastInsertRowId, close } = await initSQLite (useOpfsStorage (' test.db' , url ))
8582}
8683```
8784
@@ -92,6 +89,7 @@ Store data through `FileSystemFileHandle`, use modified `OPFSAnyContextVFS` with
9289[ minimal File System Access backend browser version] ( https://caniuse.com/mdn-api_filesystemhandle )
9390
9491> [ !warning]
92+ >
9593> 1 . maybe have perfarmance issue on Windows with device's local file, see in [ #5 ] ( https://github.com/subframe7536/sqlite-wasm/pull/5 )
9694> 2 . Safari is not supported, see in [ caniuse] ( https://caniuse.com/mdn-api_filesystemwritablefilestream )
9795
@@ -108,7 +106,7 @@ const root = await window.showDirectoryPicker()
108106const root1 = await navigator .storage .getDirectory ()
109107
110108const { run, changes, lastInsertRowId, close } = await initSQLite (
111- useFsHandleStorage (' test.db' , root , url )
109+ useFsHandleStorage (' test.db' , root , url ),
112110)
113111```
114112
@@ -141,9 +139,7 @@ async function selectFile(): Promise<File> {
141139 input .click ()
142140 })
143141}
144- const FileOrReadableStream = remote
145- ? (await fetch (remoteSqliteURL )).body !
146- : await selectFile ()
142+ const FileOrReadableStream = remote ? (await fetch (remoteSqliteURL )).body ! : await selectFile ()
147143```
148144
149145Import while initiaizing
@@ -152,9 +148,7 @@ Import while initiaizing
152148import { initSQLite , withExistDB } from ' @subframe7536/sqlite-wasm'
153149import { useIdbStorage } from ' @subframe7536/sqlite-wasm/idb'
154150
155- const db = initSQLite (
156- useIdbStorage (' test.db' , withExistDB (FileOrReadableStream , { url }))
157- )
151+ const db = initSQLite (useIdbStorage (' test.db' , withExistDB (FileOrReadableStream , { url })))
158152```
159153
160154or load it later
@@ -196,9 +190,7 @@ import { customFunction, initSQLite, isOpfsSupported } from '@subframe7536/sqlit
196190import { useOpfsStorage } from ' @subframe7536/sqlite-wasm/opfs'
197191import { uuidv7 } from ' uuidv7'
198192
199- const { run, sqlite, db } = await initSQLite (
200- useOpfsStorage (' test' )
201- )
193+ const { run, sqlite, db } = await initSQLite (useOpfsStorage (' test' ))
202194customFunction (sqlite , db , ' uuidv7' , () => uuidv7 ())
203195console .log (await run (' select uuidv7() as a' ))
204196// [{ "a": "01932f1b-b663-7714-af4d-17a3d9efc7b3" }]
@@ -225,7 +217,7 @@ for await (const row of iterator(core, 'select * from test')) {
225217 console .log (row )
226218}
227219
228- customFunctionCore (core , ' test' , num => num )
220+ customFunctionCore (core , ' test' , ( num ) => num )
229221await run (core , ' select test(?)' , [1 ])
230222
231223const buf = await exportDatabase (core .vfs , core .path )
@@ -235,8 +227,12 @@ await close(core)
235227
236228### Utils
237229
238- ``` ts
239- function dumpVFS(vfs : FacadeVFS , path : string , onDone ? : (vfs : FacadeVFS , path : string ) => any ): ReadableStream
230+ ```` ts
231+ function dumpVFS(
232+ vfs : FacadeVFS ,
233+ path : string ,
234+ onDone ? : (vfs : FacadeVFS , path : string ) => any ,
235+ ): ReadableStream
240236
241237function exportDatabaseFromIDB(vfs : FacadeVFS , path : string ): Promise <Uint8Array >
242238
@@ -249,15 +245,23 @@ function exportDatabaseFromFsHandle(vfs: FacadeVFS, path: string): Promise<Uint8
249245 */
250246function exportDatabase(vfs : FacadeVFS , path : string ): Promise <Uint8Array >
251247
252- function importDatabaseToIdb(vfs : FacadeVFS , path : string , stream : ReadableStream <Uint8Array >): Promise <void >
248+ function importDatabaseToIdb(
249+ vfs : FacadeVFS ,
250+ path : string ,
251+ stream : ReadableStream <Uint8Array >,
252+ ): Promise <void >
253253
254254/**
255255 * Import database from `File` or `ReadableStream`
256256 * @param vfs SQLite VFS
257257 * @param path db path
258258 * @param data existing database
259259 */
260- function importDatabase(vfs : FacadeVFS , path : string , data : File | ReadableStream <Uint8Array >): Promise <void >
260+ function importDatabase(
261+ vfs : FacadeVFS ,
262+ path : string ,
263+ data : File | ReadableStream <Uint8Array >,
264+ ): Promise <void >
261265
262266/**
263267 * check if IndexedDB and Web Locks API supported
@@ -293,17 +297,28 @@ function isModuleWorkerSupport(): boolean
293297 * // [{ "a": "01932f1b-b663-7714-af4d-17a3d9efc7b3" }]
294298 * ```
295299 */
296- function customFunction<N extends string , T extends SQLiteCompatibleType []>(sqlite : SQLiteAPI , db : number , fnName : N , fn : N extends ' ' ? never : (... args : T ) => (SQLiteCompatibleType | number []) | null , options ? : {
297- deterministic? : boolean
298- directOnly? : boolean
299- varargs? : boolean
300- }): void
301-
302- function customFunctionCore<N extends string , T extends SQLiteCompatibleType []>(core : SQLiteDBCore , fnName : N , fn : N extends ' ' ? never : (... args : T ) => (SQLiteCompatibleType | number []) | null , options ? : {
303- deterministic? : boolean
304- directOnly? : boolean
305- varargs? : boolean
306- }): void
300+ function customFunction<N extends string , T extends SQLiteCompatibleType []>(
301+ sqlite : SQLiteAPI ,
302+ db : number ,
303+ fnName : N ,
304+ fn : N extends ' ' ? never : (... args : T ) => (SQLiteCompatibleType | number []) | null ,
305+ options ? : {
306+ deterministic? : boolean
307+ directOnly? : boolean
308+ varargs? : boolean
309+ },
310+ ): void
311+
312+ function customFunctionCore<N extends string , T extends SQLiteCompatibleType []>(
313+ core : SQLiteDBCore ,
314+ fnName : N ,
315+ fn : N extends ' ' ? never : (... args : T ) => (SQLiteCompatibleType | number []) | null ,
316+ options ? : {
317+ deterministic? : boolean
318+ directOnly? : boolean
319+ varargs? : boolean
320+ },
321+ ): void
307322
308323/**
309324 * Parse options with existing database
@@ -319,24 +334,41 @@ function customFunctionCore<N extends string, T extends SQLiteCompatibleType[]>(
319334 * )
320335 * ```
321336 */
322- function withExistDB<T extends BaseStorageOptions >(data : File | ReadableStream , options ? : Omit <T , ' beforeOpen' >): T
337+ function withExistDB<T extends BaseStorageOptions >(
338+ data : File | ReadableStream ,
339+ options ? : Omit <T , ' beforeOpen' >,
340+ ): T
323341
324342function close(core : SQLiteDBCore ): Promise <void >
325343
326344function changes(core : SQLiteDBCore ): number | bigint
327345
328346function lastInsertRowId(core : SQLiteDBCore ): number | bigint
329347
330- function stream(core : SQLiteDBCore , onData : (data : Record <string , SQLiteCompatibleType >) => void , sql : string , parameters ? : SQLiteCompatibleType []): Promise <void >
331-
332- function run(core : SQLiteDBCore , sql : string , parameters ? : SQLiteCompatibleType []): Promise <Array <Record <string , SQLiteCompatibleType >>>
333-
334- function iterator(core : SQLiteDBCore , sql : string , parameters ? : SQLiteCompatibleType [], chunkSize ? : number ): AsyncIterableIterator <Record <string , SQLiteCompatibleType >[]>
348+ function stream(
349+ core : SQLiteDBCore ,
350+ onData : (data : Record <string , SQLiteCompatibleType >) => void ,
351+ sql : string ,
352+ parameters ? : SQLiteCompatibleType [],
353+ ): Promise <void >
354+
355+ function run(
356+ core : SQLiteDBCore ,
357+ sql : string ,
358+ parameters ? : SQLiteCompatibleType [],
359+ ): Promise <Array <Record <string , SQLiteCompatibleType >>>
360+
361+ function iterator(
362+ core : SQLiteDBCore ,
363+ sql : string ,
364+ parameters ? : SQLiteCompatibleType [],
365+ chunkSize ? : number ,
366+ ): AsyncIterableIterator <Record <string , SQLiteCompatibleType >[]>
335367
336368function parseOpenV2Flag(readonly ? : boolean ): number
337369
338370function reopen(core : SQLiteDBCore , readonly ? : boolean ): Promise <void >
339- ```
371+ ````
340372
341373## License
342374
0 commit comments