-
Notifications
You must be signed in to change notification settings - Fork 30.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76b80b1
commit 9b80c2d
Showing
3 changed files
with
170 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,38 @@ | ||
import common from '../common/index.js'; | ||
import { DatabaseSync } from 'node:sqlite'; | ||
import assert from 'assert'; | ||
import { test } from 'node:test'; | ||
|
||
test('database backup', async () => { | ||
const database = new DatabaseSync(':memory:'); | ||
|
||
database.exec(` | ||
CREATE TABLE data( | ||
key INTEGER PRIMARY KEY, | ||
value TEXT | ||
) STRICT | ||
`); | ||
|
||
const insert = database.prepare('INSERT INTO data (key, value) VALUES (?, ?)'); | ||
|
||
insert.run(1, 'hello'); | ||
insert.run(2, 'world'); | ||
|
||
console.log(database.prepare('SELECT * FROM data').all()); | ||
|
||
const p = await database.backup('backup.db', { | ||
sourceDb: 'main', | ||
targetDb: 'main', | ||
progress: (progress) => { | ||
console.log(progress); | ||
} | ||
}); | ||
|
||
const backup = new DatabaseSync('backup.db'); | ||
const rows = backup.prepare('SELECT * FROM data').all(); | ||
|
||
assert.deepStrictEqual(rows, [ | ||
{ __proto__: null, key: 1, value: 'hello'}, | ||
{ __proto__: null, key: 2, value: 'world' }, | ||
]); | ||
}); |