-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQLocal constructor accepts additional options: readOnly and verbose
- Loading branch information
1 parent
10f0b6a
commit ee7aa58
Showing
6 changed files
with
99 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
import { SQLocal } from '../src/index'; | ||
|
||
describe('init', () => { | ||
const databasePath = 'init-test.sqlite3'; | ||
const { sql } = new SQLocal({ databasePath }); | ||
|
||
beforeEach(async () => { | ||
await sql`CREATE TABLE nums (num INTEGER NOT NULL)`; | ||
await sql`INSERT INTO nums (num) VALUES (0)`; | ||
}); | ||
|
||
afterEach(async () => { | ||
await sql`DROP TABLE nums`; | ||
}); | ||
|
||
afterAll(async () => { | ||
const opfs = await navigator.storage.getDirectory(); | ||
await opfs.removeEntry(databasePath); | ||
}); | ||
|
||
it('should be cross-origin isolated', () => { | ||
expect(crossOriginIsolated).toBe(true); | ||
}); | ||
|
||
it('should create a file in the OPFS', async () => { | ||
const opfs = await navigator.storage.getDirectory(); | ||
const fileHandle = await opfs.getFileHandle(databasePath); | ||
const file = await fileHandle.getFile(); | ||
expect(file.size).toBeGreaterThan(0); | ||
}); | ||
|
||
it('should enable read-only mode', async () => { | ||
const { sql, destroy } = new SQLocal({ | ||
databasePath, | ||
readOnly: true, | ||
}); | ||
|
||
const write = async () => { | ||
await sql`INSERT INTO nums (num) VALUES (1)`; | ||
}; | ||
expect(write).rejects.toThrowError( | ||
'SQLITE_IOERR_WRITE: sqlite3 result code 778: disk I/O error' | ||
); | ||
|
||
const read = async () => { | ||
return await sql`SELECT * FROM nums`; | ||
}; | ||
const data = await read(); | ||
expect(data).toEqual([{ num: 0 }]); | ||
|
||
await destroy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters