Skip to content

Commit 10ed2a7

Browse files
committed
Assert powersync_control is called in transactions only
1 parent 9e737ec commit 10ed2a7

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

crates/core/src/sync/interface.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub fn register(db: *mut sqlite::sqlite3) -> Result<(), ResultCode> {
125125
argv: *mut *mut sqlite::value,
126126
) -> () {
127127
let result = (|| -> Result<(), SQLiteError> {
128+
debug_assert!(!ctx.db_handle().get_autocommit());
129+
128130
let controller = unsafe { ctx.user_data().cast::<SqlController>().as_mut() }
129131
.ok_or_else(|| SQLiteError::from(ResultCode::INTERNAL))?;
130132

dart/test/sync_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ void _syncTests<T>({
4949
late SyncLinesGoldenTest matcher;
5050

5151
List<Object?> invokeControlRaw(String operation, Object? data) {
52+
db.execute('begin');
5253
final [row] =
5354
db.select('SELECT powersync_control(?, ?)', [operation, data]);
55+
db.execute('commit');
5456
return jsonDecode(row.columnAt(0));
5557
}
5658

@@ -59,9 +61,7 @@ void _syncTests<T>({
5961
// Trace through golden matcher
6062
return matcher.invoke(operation, data);
6163
} else {
62-
final [row] =
63-
db.select('SELECT powersync_control(?, ?)', [operation, data]);
64-
return jsonDecode(row.columnAt(0));
64+
return invokeControlRaw(operation, data);
6565
}
6666
}
6767

docs/sync.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sync line sent from a PowerSync service instance.
55

66
After registering the PowerSync extension, this client is available through the `powersync_control`
77
function, which takes two arguments: A command (text), and a payload (text, blob, or null).
8+
The function should always be called in a transaction.
89

910
The following commands are supported:
1011

0 commit comments

Comments
 (0)