Skip to content

Commit

Permalink
[sembast] feat work on supporting read-only db
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Dec 3, 2024
1 parent e1755f9 commit 55af734
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions sembast/lib/src/database_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ class SembastDatabase extends Object
// Not record, no commit
if (txnRecords.isNotEmpty) {
void saveInMemory() {
if (isReadOnly) {
throw DatabaseException.badParam('Read-only database');
}
for (var record in txnRecords) {
final exists = setRecordInMemory(record);
// Try to estimated if compact will be needed
Expand Down Expand Up @@ -1367,9 +1370,6 @@ class SembastDatabase extends Object

/// Replay the transaction if something has changed
if (commitEntries.hasWriteData || commitEntries.upgrading) {
if (isReadOnly) {
throw DatabaseException.badParam('Read-only database');
}
// Build Entries
var entries = <JdbWriteEntry>[];
for (var record in commitEntries.txnRecords!) {
Expand Down
2 changes: 1 addition & 1 deletion sembast/test/database_format_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void defineTestsWithCodec(FileSystemTestContext ctx, {SembastCodec? codec}) {
// Read-only database
//print(_);
}
expect(await record2.get(db), 'ho'); // ! read-only but not in memory
expect(await record2.get(db), isNull); // ! read-only but not in memory
await db.close();
db = await factory.openDatabase(dbPath, mode: DatabaseMode.readOnly);
expect(await record2.get(db), isNull);
Expand Down
4 changes: 2 additions & 2 deletions sembast_test/lib/open_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ void defineTests(DatabaseTestContext ctx) {
expect(await record2.get(db), isNull);
try {
await record2.put(db, 'ho');
//fail('should fail');
fail('should fail');
} on DatabaseException catch (_) {
// Read-only database
// print(_);
}
// expect(await record2.get(db), 'ho'); // ! read-only but not in memory
expect(await record2.get(db), isNull); // ! read-only but not in memory
await db.close();
db = await factory.openDatabase(dbPath, mode: DatabaseMode.readOnly);
// expect(await record2.get(db), isNull); to test
Expand Down

0 comments on commit 55af734

Please sign in to comment.