Skip to content

Commit f9a1ccb

Browse files
committed
feat: fts5 support
1 parent fe46920 commit f9a1ccb

File tree

11 files changed

+109
-23
lines changed

11 files changed

+109
-23
lines changed

README.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
## sqlite-wasm
1+
# sqlite-wasm
22

3-
typesafe [wa-sqlite](https://github.com/rhashimoto/wa-sqlite) wrapper, run in memory or persist data to IndexedDB or [OPFS](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system)
3+
Typesafe [custom wa-sqlite](https://github.com/subframe7536/sqwab/releases/tag/v1729389754) wrapper, run in memory or persist data to IndexedDB or [OPFS](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system), support FTS5 and update / delete limit
44

5-
low-level layer for [kysely-wasqlite-worker-dialect](https://github.com/subframe7536/kysely-sqlite-tools/tree/master/packages/dialect-wasqlite-worker)
5+
Low-level layer for [kysely-wasqlite-worker-dialect](https://github.com/subframe7536/kysely-sqlite-tools/tree/master/packages/dialect-wasqlite-worker)
66

7-
### Usage
7+
## Usage
88

9-
#### Memory
9+
### Memory
1010

11-
use MemoryVFS with `wa-sqlite.wasm`, no data persistence
11+
Use `MemoryVFS` with `wa-sqlite.wasm`, no data persistence
1212

1313
```ts
14-
import { getSyncWasmURL, initSQLite, isOpfsSupported, useMemoryStorage } from '@subframe7536/sqlite-wasm'
14+
import { initSQLite, isOpfsSupported, useMemoryStorage } from '@subframe7536/sqlite-wasm'
1515

1616
// optional url
1717
const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite.wasm'
@@ -21,14 +21,14 @@ const { run, changes, lastInsertRowId, close } = await initSQLite(
2121
)
2222
```
2323

24-
#### IndexedDB
24+
### IndexedDB
2525

2626
use `IDBBatchAtomicVFS` with `wa-sqlite-async.wasm`, larger than sync version, better compatibility
2727

2828
[minimal IndexedDB backend browser version](https://caniuse.com/mdn-api_lockmanager)
2929

3030
```ts
31-
import { getAsyncWasmURL, initSQLite } from '@subframe7536/sqlite-wasm'
31+
import { initSQLite } from '@subframe7536/sqlite-wasm'
3232
import { useIdbStorage } from '@subframe7536/sqlite-wasm/idb'
3333

3434
// optional url
@@ -39,7 +39,23 @@ const { run, changes, lastInsertRowId, close } = await initSQLite(
3939
)
4040
```
4141

42-
#### OPFS
42+
#### IdbMemory
43+
44+
Use `IDBMirrorVFS` with `wa-sqlite-async.wasm` (larger than sync version), better performance compare to `useIdbStorage`, store data in memory and sync to IndexedDB.
45+
46+
```ts
47+
import { initSQLite } from '@subframe7536/sqlite-wasm'
48+
import { useIdbMemoryStorage } from '@subframe7536/sqlite-wasm/idb'
49+
50+
// optional url
51+
const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'
52+
53+
const { run, changes, lastInsertRowId, close } = await initSQLite(
54+
useIdbMemoryStorage('IndexedDB', { url })
55+
)
56+
```
57+
58+
### OPFS
4359

4460
use `OPFSCoopSyncVFS` with `wa-sqlite.wasm`, smaller than async version
4561

@@ -48,7 +64,7 @@ use `OPFSCoopSyncVFS` with `wa-sqlite.wasm`, smaller than async version
4864
**MUST RUN IN WEB WORKER**
4965

5066
```ts
51-
import { getSyncWasmURL, initSQLite, isOpfsSupported } from '@subframe7536/sqlite-wasm'
67+
import { initSQLite, isOpfsSupported } from '@subframe7536/sqlite-wasm'
5268
import { useOpfsStorage } from '@subframe7536/sqlite-wasm/opfs'
5369

5470
// optional url
@@ -63,3 +79,23 @@ onmessage = async () => {
6379
)
6480
}
6581
```
82+
83+
### Custom Function
84+
85+
```ts
86+
import { def, initSQLite, useMemoryStorage } from '@subframe7536/sqlite-wasm'
87+
88+
// optional url
89+
const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite.wasm'
90+
91+
const { sqlite, db, run } = await initSQLite(useMemoryStorage({ url }))
92+
93+
def(sqlite, db, 'testFn', (a: number, b: number) => a + b)
94+
95+
await run('select testFn(1,2) as a')
96+
// [{ a: 3 }]
97+
```
98+
99+
## License
100+
101+
MIT

src/vfs/idb.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BaseOptions, IDBBatchAtomicVFSOptions, Options } from '../types'
2-
import SQLiteAsyncESMFactory from 'wa-sqlite/dist/wa-sqlite-async.mjs'
32
import { IDBBatchAtomicVFS } from 'wa-sqlite/src/examples/IDBBatchAtomicVFS.js'
43
import { IDBMirrorVFS } from 'wa-sqlite/src/examples/IDBMirrorVFS.js'
4+
import SQLiteAsyncESMFactory from '../../wa-sqlite-fts5/wa-sqlite-async.mjs'
55

66
export { IDBBatchAtomicVFS } from 'wa-sqlite/src/examples/IDBBatchAtomicVFS.js'
77
export { IDBMirrorVFS } from 'wa-sqlite/src/examples/IDBMirrorVFS.js'
@@ -16,10 +16,9 @@ export type IDBVFSOptions = IDBBatchAtomicVFSOptions
1616
* @example
1717
* ```ts
1818
* import { useIdbStorage } from '@subframe7536/sqlite-wasm/idb'
19-
* import { getAsyncWasmURL, initSQLite } from '@subframe7536/sqlite-wasm'
19+
* import { initSQLite } from '@subframe7536/sqlite-wasm'
2020
*
21-
* // const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'
22-
* const url = getAsyncWasmURL()
21+
* const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'
2322
*
2423
* const { run, changes, lastInsertRowId, close, sqlite, db } = await initSQLite(
2524
* useIdbStorage('test', { url })
@@ -59,10 +58,9 @@ export async function useIdbStorage(
5958
* @example
6059
* ```ts
6160
* import { useIdbMemoryStorage } from '@subframe7536/sqlite-wasm/idb'
62-
* import { getAsyncWasmURL, initSQLite } from '@subframe7536/sqlite-wasm'
61+
* import { initSQLite } from '@subframe7536/sqlite-wasm'
6362
*
64-
* // const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'
65-
* const url = getAsyncWasmURL()
63+
* const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'
6664
*
6765
* const { run, changes, lastInsertRowId, close, sqlite, db } = await initSQLite(
6866
* useIdbMemoryStorage('test', { url })

src/vfs/memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BaseOptions, Options } from '../types'
2-
import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs'
32
import { MemoryVFS } from 'wa-sqlite/src/examples/MemoryVFS.js'
3+
import SQLiteESMFactory from '../../wa-sqlite-fts5/wa-sqlite.mjs'
44

55
export { MemoryVFS } from 'wa-sqlite/src/examples/MemoryVFS.js'
66

src/vfs/opfs.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BaseOptions, Options } from '../types'
2-
import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs'
32
import { OPFSCoopSyncVFS } from 'wa-sqlite/src/examples/OPFSCoopSyncVFS.js'
3+
import SQLiteESMFactory from '../../wa-sqlite-fts5/wa-sqlite.mjs'
44

55
export { OPFSCoopSyncVFS } from 'wa-sqlite/src/examples/OPFSCoopSyncVFS.js'
66

@@ -13,11 +13,10 @@ export { OPFSCoopSyncVFS } from 'wa-sqlite/src/examples/OPFSCoopSyncVFS.js'
1313
* @param options wasm file url
1414
* @example
1515
* // only effect in worker
16-
* import { getSyncWasmURL, initSQLite, isOpfsSupported } from '@subframe7536/sqlite-wasm'
16+
* import { initSQLite, isOpfsSupported } from '@subframe7536/sqlite-wasm'
1717
* import { useOpfsStorage } from '@subframe7536/sqlite-wasm/opfs'
1818
*
19-
* // const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite.wasm',
20-
* const url = getSyncWasmURL()
19+
* const url = 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite.wasm'
2120
*
2221
* onmessage = async () => {
2322
* if (!isOpfsSupported()) {

wa-sqlite-fts5/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# wa-sqlite fts5
2+
3+
Download from https://github.com/subframe7536/sqwab/releases
4+
5+
Tag: `v1729389754`

wa-sqlite-fts5/wa-sqlite-async.mjs

Lines changed: 16 additions & 0 deletions
Large diffs are not rendered by default.
1.36 MB
Binary file not shown.

wa-sqlite-fts5/wa-sqlite-jspi.mjs

Lines changed: 16 additions & 0 deletions
Large diffs are not rendered by default.

wa-sqlite-fts5/wa-sqlite-jspi.wasm

693 KB
Binary file not shown.

wa-sqlite-fts5/wa-sqlite.mjs

Lines changed: 16 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)