Skip to content

Commit 9e9b396

Browse files
committed
feat(docs): add database restoration section to README and comprehensive tests for backup restoration
1 parent b0eac34 commit 9e9b396

File tree

3 files changed

+444
-1
lines changed

3 files changed

+444
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,26 @@ await db.backup("./other-backup.db", {
136136
});
137137
```
138138

139+
### Database Restoration
140+
141+
```typescript
142+
// Restore from a backup file
143+
import * as fs from "fs";
144+
145+
// Close the current database
146+
db.close();
147+
148+
// Copy the backup file over the current database file
149+
fs.copyFileSync("./backup.db", "./mydata.db");
150+
151+
// Reopen the database with the restored data
152+
const restoredDb = new DatabaseSync("./mydata.db");
153+
154+
// Verify restoration
155+
const count = restoredDb.prepare("SELECT COUNT(*) as count FROM users").get();
156+
console.log(`Restored database has ${count.count} users`);
157+
```
158+
139159
### Session-based Change Tracking
140160

141161
SQLite's session extension allows you to record changes and apply them to other databases - perfect for synchronization, replication, or undo/redo functionality. This feature is available in both `node:sqlite` and `@photostructure/sqlite`, but not in better-sqlite3.

TODO.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ This document tracks the remaining tasks to complete the SQLite extraction from
240240
-**Progress callbacks** for monitoring backup progress
241241
-**Rate parameter** matching Node.js API (negative values supported)
242242
-**Comprehensive tests** covering all backup scenarios and metadata preservation
243+
-**Backup restoration tests** - 7 comprehensive tests covering restoration scenarios
243244

244245
8. **✅ API Naming Compatibility** (COMPLETED)
245246

@@ -285,7 +286,7 @@ This document tracks the remaining tasks to complete the SQLite extraction from
285286

286287
-**Core SQLite operations working** (CREATE, INSERT, SELECT, UPDATE, DELETE)
287288
-**Advanced SQLite features working** (user functions, aggregates, iterators, sessions, backup, and enhanced location method all fully functional)
288-
-**280 tests passing** with comprehensive coverage across all features:
289+
-**287 tests passing** with comprehensive coverage across all features:
289290
- ✅ 13 basic database tests
290291
- ✅ 13 configuration option tests
291292
- ✅ 8 user-defined function tests
@@ -298,6 +299,7 @@ This document tracks the remaining tasks to complete the SQLite extraction from
298299
- ✅ 14 extension loading tests
299300
- ✅ 28 SQLite session tests (with changeset content verification!)
300301
- ✅ 14 backup functionality tests (with Node.js API compatibility and rate validation)
302+
- ✅ 7 backup restoration tests (with schema, triggers, and pragma preservation)
301303
- ✅ 10 enhanced location method tests (with attached database support)
302304
- ✅ 26 error handling tests (with constraint violations and recovery)
303305
- ✅ 17 STRICT tables tests (with type enforcement and constraints)

0 commit comments

Comments
 (0)