Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion powersync/src/db/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl InnerPowerSyncState {
if let Some(write_checkpoint) = write_checkpoint {
// If there are no remaining crud items we can set the target op to the checkpoint.
let stmt = writer.inner.prepare("SELECT 1 FROM ps_crud LIMIT 1")?;
if let ResultCode::OK = stmt.step()? {
if let ResultCode::DONE = stmt.step()? {
target_op = write_checkpoint;
}
}
Expand Down
30 changes: 30 additions & 0 deletions powersync/tests/crud_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,36 @@ fn insert() {
});
}

#[test]
fn applies_checkpoint_after_draining_crud_queue() {
future::block_on(async move {
let test = DatabaseTest::new();
let db = test.in_memory_database();

execute(
&db,
"INSERT INTO users (id, name) VALUES (?, ?)",
params!["test", "name"],
)
.await;

let transaction = db.next_crud_transaction().await.unwrap().unwrap();
transaction.complete_with_checkpoint(42).await.unwrap();

let mut reader = db.reader().await.unwrap();
let reader = reader.transaction().unwrap();
let checkpoint: i64 = reader
.query_one(
"SELECT powersync_control('target_checkpoint_request_id', NULL)",
params![],
|row| row.get(0),
)
.unwrap();

assert_eq!(checkpoint, 42);
});
}

#[test]
fn crud_transactions() {
async fn create_transaction(db: &PowerSyncDatabase, amount: usize) {
Expand Down
Loading