@livestore/wa-sqlite 0.4.0-dev.21 → 0.4.0-dev.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -36
- package/dist/README.md +13 -13
- package/dist/fts5/wa-sqlite.mjs +1 -1
- package/dist/fts5/wa-sqlite.node.mjs +1 -1
- package/dist/fts5/wa-sqlite.node.wasm +0 -0
- package/dist/fts5/wa-sqlite.wasm +0 -0
- package/dist/wa-sqlite-async.mjs +1 -1
- package/dist/wa-sqlite-async.wasm +0 -0
- package/dist/wa-sqlite-jspi.mjs +1 -1
- package/dist/wa-sqlite-jspi.wasm +0 -0
- package/dist/wa-sqlite.mjs +1 -1
- package/dist/wa-sqlite.node.mjs +1 -1
- package/dist/wa-sqlite.node.wasm +0 -0
- package/dist/wa-sqlite.wasm +0 -0
- package/package.json +40 -29
- package/src/FacadeVFS.js +252 -261
- package/src/VFS.js +84 -85
- package/src/WebLocksMixin.js +357 -351
- package/src/examples/AccessHandlePoolVFS.js +185 -194
- package/src/examples/IDBBatchAtomicVFS.js +429 -409
- package/src/examples/IDBMirrorVFS.js +402 -409
- package/src/examples/MemoryAsyncVFS.js +32 -37
- package/src/examples/MemoryVFS.js +71 -75
- package/src/examples/OPFSAdaptiveVFS.js +206 -206
- package/src/examples/OPFSAnyContextVFS.js +141 -140
- package/src/examples/OPFSCoopSyncVFS.js +297 -299
- package/src/examples/OPFSPermutedVFS.js +529 -540
- package/src/examples/README.md +27 -15
- package/src/examples/tag.js +27 -27
- package/src/sqlite-api.js +910 -941
- package/src/sqlite-constants.js +246 -232
- package/src/types/globals.d.ts +52 -52
- package/src/types/index.d.ts +586 -576
- package/test/AccessHandlePoolVFS.test.js +21 -21
- package/test/IDBBatchAtomicVFS.test.js +69 -69
- package/test/IDBMirrorVFS.test.js +21 -21
- package/test/MemoryAsyncVFS.test.js +21 -21
- package/test/MemoryVFS.test.js +21 -21
- package/test/OPFSAdaptiveVFS.test.js +21 -21
- package/test/OPFSAnyContextVFS.test.js +21 -21
- package/test/OPFSCoopSyncVFS.test.js +21 -21
- package/test/OPFSPermutedVFS.test.js +21 -21
- package/test/TestContext.js +44 -41
- package/test/WebLocksMixin.test.js +369 -360
- package/test/api.test.js +23 -23
- package/test/api_exec.js +72 -61
- package/test/api_misc.js +53 -54
- package/test/api_statements.js +271 -279
- package/test/callbacks.test.js +492 -478
- package/test/data/idbv5.json +1135 -1
- package/test/sql.test.js +30 -30
- package/test/sql_0001.js +49 -33
- package/test/sql_0002.js +55 -34
- package/test/sql_0003.js +85 -49
- package/test/sql_0004.js +76 -47
- package/test/sql_0005.js +60 -44
- package/test/test-worker.js +171 -163
- package/test/vfs_xAccess.js +1 -2
- package/test/vfs_xClose.js +50 -49
- package/test/vfs_xOpen.js +73 -72
- package/test/vfs_xRead.js +31 -31
- package/test/vfs_xWrite.js +30 -29
package/test/api.test.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { api_exec } from './api_exec.js'
|
|
2
|
+
import { api_misc } from './api_misc.js'
|
|
3
|
+
import { api_statements } from './api_statements.js'
|
|
4
|
+
import { TestContext } from './TestContext.js'
|
|
5
5
|
|
|
6
|
-
const ALL_BUILDS = ['default', 'asyncify']
|
|
7
|
-
const ASYNC_BUILDS = ['asyncify']
|
|
6
|
+
const ALL_BUILDS = ['default', 'asyncify']
|
|
7
|
+
const ASYNC_BUILDS = ['asyncify']
|
|
8
8
|
|
|
9
|
-
const supportsJSPI = await TestContext.supportsJSPI()
|
|
9
|
+
const supportsJSPI = await TestContext.supportsJSPI()
|
|
10
10
|
if (supportsJSPI) {
|
|
11
|
-
ALL_BUILDS.push('jspi')
|
|
12
|
-
ASYNC_BUILDS.push('jspi')
|
|
11
|
+
ALL_BUILDS.push('jspi')
|
|
12
|
+
ASYNC_BUILDS.push('jspi')
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/** @type {Map<string, string[]>} */
|
|
@@ -24,26 +24,26 @@ const CONFIGS = new Map([
|
|
|
24
24
|
['OPFSAdaptiveVFS', ASYNC_BUILDS],
|
|
25
25
|
['OPFSAnyContextVFS', ASYNC_BUILDS],
|
|
26
26
|
['OPFSPermutedVFS', ASYNC_BUILDS],
|
|
27
|
-
])
|
|
27
|
+
])
|
|
28
28
|
|
|
29
|
-
describe('SQLite API', function() {
|
|
29
|
+
describe('SQLite API', function () {
|
|
30
30
|
for (const [config, builds] of CONFIGS) {
|
|
31
|
-
describe(config, function() {
|
|
31
|
+
describe(config, function () {
|
|
32
32
|
for (const build of builds) {
|
|
33
|
-
describe(build, function() {
|
|
34
|
-
apiSpecs(build, config)
|
|
35
|
-
})
|
|
33
|
+
describe(build, function () {
|
|
34
|
+
apiSpecs(build, config)
|
|
35
|
+
})
|
|
36
36
|
}
|
|
37
|
-
})
|
|
37
|
+
})
|
|
38
38
|
}
|
|
39
|
-
})
|
|
39
|
+
})
|
|
40
40
|
|
|
41
41
|
function apiSpecs(build, config) {
|
|
42
|
-
const context = new TestContext({ build, config })
|
|
42
|
+
const context = new TestContext({ build, config })
|
|
43
43
|
|
|
44
|
-
describe(`SQLite ${build} ${config}`, function() {
|
|
45
|
-
api_exec(context)
|
|
46
|
-
api_misc(context)
|
|
47
|
-
api_statements(context)
|
|
48
|
-
})
|
|
44
|
+
describe(`SQLite ${build} ${config}`, function () {
|
|
45
|
+
api_exec(context)
|
|
46
|
+
api_misc(context)
|
|
47
|
+
api_statements(context)
|
|
48
|
+
})
|
|
49
49
|
}
|
package/test/api_exec.js
CHANGED
|
@@ -1,70 +1,80 @@
|
|
|
1
|
-
import * as Comlink from 'comlink'
|
|
2
|
-
|
|
1
|
+
import * as Comlink from 'comlink'
|
|
2
|
+
|
|
3
|
+
import * as SQLite from '../src/sqlite-api.js'
|
|
3
4
|
|
|
4
5
|
export function api_exec(context) {
|
|
5
|
-
describe('exec', function() {
|
|
6
|
-
let proxy, sqlite3, db
|
|
7
|
-
beforeEach(async function() {
|
|
8
|
-
proxy = await context.create()
|
|
9
|
-
sqlite3 = proxy.sqlite3
|
|
10
|
-
db = await sqlite3.open_v2('demo')
|
|
11
|
-
})
|
|
6
|
+
describe('exec', function () {
|
|
7
|
+
let proxy, sqlite3, db
|
|
8
|
+
beforeEach(async function () {
|
|
9
|
+
proxy = await context.create()
|
|
10
|
+
sqlite3 = proxy.sqlite3
|
|
11
|
+
db = await sqlite3.open_v2('demo')
|
|
12
|
+
})
|
|
12
13
|
|
|
13
|
-
afterEach(async function() {
|
|
14
|
-
await sqlite3.close(db)
|
|
15
|
-
await context.destroy(proxy)
|
|
16
|
-
})
|
|
14
|
+
afterEach(async function () {
|
|
15
|
+
await sqlite3.close(db)
|
|
16
|
+
await context.destroy(proxy)
|
|
17
|
+
})
|
|
17
18
|
|
|
18
|
-
it('should execute a query', async function() {
|
|
19
|
-
let rc
|
|
20
|
-
rc = await sqlite3.exec(db, 'CREATE TABLE t(x)')
|
|
21
|
-
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
19
|
+
it('should execute a query', async function () {
|
|
20
|
+
let rc
|
|
21
|
+
rc = await sqlite3.exec(db, 'CREATE TABLE t(x)')
|
|
22
|
+
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
22
23
|
|
|
23
|
-
rc = await sqlite3.exec(db, 'INSERT INTO t VALUES (1), (2), (3)')
|
|
24
|
-
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
24
|
+
rc = await sqlite3.exec(db, 'INSERT INTO t VALUES (1), (2), (3)')
|
|
25
|
+
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
25
26
|
|
|
26
|
-
const nChanges = await sqlite3.changes(db)
|
|
27
|
-
expect(nChanges).toEqual(3)
|
|
28
|
-
})
|
|
27
|
+
const nChanges = await sqlite3.changes(db)
|
|
28
|
+
expect(nChanges).toEqual(3)
|
|
29
|
+
})
|
|
29
30
|
|
|
30
|
-
it('should execute multiple queries', async function() {
|
|
31
|
-
let rc
|
|
32
|
-
rc = await sqlite3.exec(
|
|
31
|
+
it('should execute multiple queries', async function () {
|
|
32
|
+
let rc
|
|
33
|
+
rc = await sqlite3.exec(
|
|
34
|
+
db,
|
|
35
|
+
`
|
|
33
36
|
CREATE TABLE t(x);
|
|
34
37
|
INSERT INTO t VALUES (1), (2), (3);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
`,
|
|
39
|
+
)
|
|
40
|
+
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
41
|
+
await expectAsync(sqlite3.changes(db)).toBeResolvedTo(3)
|
|
42
|
+
})
|
|
39
43
|
|
|
40
|
-
it('should return query results via callback', async function() {
|
|
41
|
-
const results = { rows: [], columns: [] }
|
|
42
|
-
const rc = await sqlite3.exec(
|
|
44
|
+
it('should return query results via callback', async function () {
|
|
45
|
+
const results = { rows: [], columns: [] }
|
|
46
|
+
const rc = await sqlite3.exec(
|
|
47
|
+
db,
|
|
48
|
+
`
|
|
43
49
|
CREATE TABLE t(x);
|
|
44
50
|
INSERT INTO t VALUES (1), (2), (3);
|
|
45
51
|
SELECT * FROM t ORDER BY x;
|
|
46
|
-
`,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
`,
|
|
53
|
+
Comlink.proxy((row, columns) => {
|
|
54
|
+
if (columns.length) {
|
|
55
|
+
results.columns = columns
|
|
56
|
+
results.rows.push(row)
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
)
|
|
60
|
+
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
61
|
+
expect(results).toEqual({ columns: ['x'], rows: [[1], [2], [3]] })
|
|
62
|
+
})
|
|
55
63
|
|
|
56
|
-
it('should allow a transaction to span multiple calls', async function() {
|
|
57
|
-
let rc
|
|
58
|
-
rc = await sqlite3.get_autocommit(db)
|
|
59
|
-
expect(rc).not.toEqual(0)
|
|
64
|
+
it('should allow a transaction to span multiple calls', async function () {
|
|
65
|
+
let rc
|
|
66
|
+
rc = await sqlite3.get_autocommit(db)
|
|
67
|
+
expect(rc).not.toEqual(0)
|
|
60
68
|
|
|
61
|
-
rc = await sqlite3.exec(db, 'BEGIN TRANSACTION')
|
|
62
|
-
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
69
|
+
rc = await sqlite3.exec(db, 'BEGIN TRANSACTION')
|
|
70
|
+
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
63
71
|
|
|
64
|
-
rc = await sqlite3.get_autocommit(db)
|
|
65
|
-
expect(rc).toEqual(0)
|
|
72
|
+
rc = await sqlite3.get_autocommit(db)
|
|
73
|
+
expect(rc).toEqual(0)
|
|
66
74
|
|
|
67
|
-
rc = await sqlite3.exec(
|
|
75
|
+
rc = await sqlite3.exec(
|
|
76
|
+
db,
|
|
77
|
+
`
|
|
68
78
|
CREATE TABLE t AS
|
|
69
79
|
WITH RECURSIVE cnt(x) AS (
|
|
70
80
|
SELECT 1
|
|
@@ -73,17 +83,18 @@ export function api_exec(context) {
|
|
|
73
83
|
LIMIT 100
|
|
74
84
|
)
|
|
75
85
|
SELECT x FROM cnt;
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
`,
|
|
87
|
+
)
|
|
88
|
+
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
78
89
|
|
|
79
|
-
rc = await sqlite3.get_autocommit(db)
|
|
80
|
-
expect(rc).toEqual(0)
|
|
90
|
+
rc = await sqlite3.get_autocommit(db)
|
|
91
|
+
expect(rc).toEqual(0)
|
|
81
92
|
|
|
82
|
-
rc = await sqlite3.exec(db, 'COMMIT')
|
|
83
|
-
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
93
|
+
rc = await sqlite3.exec(db, 'COMMIT')
|
|
94
|
+
expect(rc).toEqual(SQLite.SQLITE_OK)
|
|
84
95
|
|
|
85
|
-
rc = await sqlite3.get_autocommit(db)
|
|
86
|
-
expect(rc).not.toEqual(0)
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
}
|
|
96
|
+
rc = await sqlite3.get_autocommit(db)
|
|
97
|
+
expect(rc).not.toEqual(0)
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
}
|
package/test/api_misc.js
CHANGED
|
@@ -1,63 +1,62 @@
|
|
|
1
|
-
import * as SQLite from '../src/sqlite-api.js'
|
|
1
|
+
import * as SQLite from '../src/sqlite-api.js'
|
|
2
2
|
|
|
3
3
|
export function api_misc(context) {
|
|
4
|
-
describe('libversion', function() {
|
|
5
|
-
let proxy, sqlite3, db
|
|
6
|
-
beforeEach(async function() {
|
|
7
|
-
proxy = await context.create()
|
|
8
|
-
sqlite3 = proxy.sqlite3
|
|
9
|
-
db = await sqlite3.open_v2('demo')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
afterEach(async function() {
|
|
13
|
-
await sqlite3.close(db)
|
|
14
|
-
await context.destroy(proxy)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should return the library version', async function() {
|
|
18
|
-
const versionString = await sqlite3.libversion()
|
|
19
|
-
expect(versionString).toMatch(/^\d+\.\d+\.\d+$/)
|
|
20
|
-
|
|
21
|
-
const components = versionString.split('.')
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
await
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
it('should constrain usage', async function() {
|
|
4
|
+
describe('libversion', function () {
|
|
5
|
+
let proxy, sqlite3, db
|
|
6
|
+
beforeEach(async function () {
|
|
7
|
+
proxy = await context.create()
|
|
8
|
+
sqlite3 = proxy.sqlite3
|
|
9
|
+
db = await sqlite3.open_v2('demo')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
afterEach(async function () {
|
|
13
|
+
await sqlite3.close(db)
|
|
14
|
+
await context.destroy(proxy)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('should return the library version', async function () {
|
|
18
|
+
const versionString = await sqlite3.libversion()
|
|
19
|
+
expect(versionString).toMatch(/^\d+\.\d+\.\d+$/)
|
|
20
|
+
|
|
21
|
+
const components = versionString.split('.').map((component, i) => {
|
|
22
|
+
return i ? component.padStart(3, '0') : component
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const versionNumber = await sqlite3.libversion_number()
|
|
26
|
+
expect(versionNumber.toString()).toEqual(components.join(''))
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
describe('limit', function () {
|
|
31
|
+
let proxy, sqlite3, db
|
|
32
|
+
beforeEach(async function () {
|
|
33
|
+
proxy = await context.create()
|
|
34
|
+
sqlite3 = proxy.sqlite3
|
|
35
|
+
db = await sqlite3.open_v2('demo')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
afterEach(async function () {
|
|
39
|
+
await sqlite3.close(db)
|
|
40
|
+
await context.destroy(proxy)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should constrain usage', async function () {
|
|
45
44
|
const sql = `
|
|
46
45
|
SELECT 1, 2, 3, 4, 5, 6;
|
|
47
|
-
`.trim()
|
|
46
|
+
`.trim()
|
|
48
47
|
|
|
49
|
-
let rc
|
|
50
|
-
await expectAsync(sqlite3.exec(db, sql)).toBeResolvedTo(SQLite.SQLITE_OK)
|
|
48
|
+
let rc
|
|
49
|
+
await expectAsync(sqlite3.exec(db, sql)).toBeResolvedTo(SQLite.SQLITE_OK)
|
|
51
50
|
|
|
52
|
-
rc = await sqlite3.limit(db, SQLite.SQLITE_LIMIT_COLUMN, 5)
|
|
53
|
-
expect(rc).toBeGreaterThan(0)
|
|
51
|
+
rc = await sqlite3.limit(db, SQLite.SQLITE_LIMIT_COLUMN, 5)
|
|
52
|
+
expect(rc).toBeGreaterThan(0)
|
|
54
53
|
|
|
55
|
-
await expectAsync(sqlite3.exec(db, sql)).toBeRejectedWithError(/too many columns/)
|
|
54
|
+
await expectAsync(sqlite3.exec(db, sql)).toBeRejectedWithError(/too many columns/)
|
|
56
55
|
|
|
57
|
-
rc = await sqlite3.limit(db, SQLite.SQLITE_LIMIT_COLUMN, rc)
|
|
58
|
-
expect(rc).toEqual(5)
|
|
56
|
+
rc = await sqlite3.limit(db, SQLite.SQLITE_LIMIT_COLUMN, rc)
|
|
57
|
+
expect(rc).toEqual(5)
|
|
59
58
|
|
|
60
|
-
await expectAsync(sqlite3.exec(db, sql)).toBeResolvedTo(SQLite.SQLITE_OK)
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
}
|
|
59
|
+
await expectAsync(sqlite3.exec(db, sql)).toBeResolvedTo(SQLite.SQLITE_OK)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
}
|