-
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.
Fix database returning stale data after calling overwriteDatabaseFile…
… on it
- Loading branch information
1 parent
4148bfa
commit 8017f99
Showing
3 changed files
with
32 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, it, expect, afterAll } from 'vitest'; | ||
import { SQLocal } from '../src/index'; | ||
|
||
describe('overwriteDatabaseFile', async () => { | ||
const db1 = new SQLocal('overwrite-test-db1.sqlite3'); | ||
const db2 = new SQLocal('overwrite-test-db2.sqlite3'); | ||
|
||
await db1.sql`CREATE TABLE letters (letter TEXT NOT NULL)`; | ||
await db1.sql`INSERT INTO letters (letter) VALUES ('a'), ('b'), ('c')`; | ||
|
||
await db2.sql`CREATE TABLE nums (num INTEGER NOT NULL)`; | ||
await db2.sql`INSERT INTO nums (num) VALUES (1), (2), (3)`; | ||
|
||
afterAll(async () => { | ||
const opfs = await navigator.storage.getDirectory(); | ||
await opfs.removeEntry('overwrite-test-db1.sqlite3'); | ||
await opfs.removeEntry('overwrite-test-db2.sqlite3'); | ||
}); | ||
|
||
it('should replace the contents of a database', async () => { | ||
const db2File = await db2.getDatabaseFile(); | ||
await db1.overwriteDatabaseFile(db2File); | ||
|
||
const letters = db1.sql`SELECT * FROM letters`; | ||
expect(letters).rejects.toThrow(); | ||
const nums = db1.sql`SELECT * FROM nums`; | ||
expect(nums).resolves.toEqual([{ num: 1 }, { num: 2 }, { num: 3 }]); | ||
}); | ||
}); |
8017f99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixed a bug in my app, thank you!
8017f99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing! Glad to hear it