Skip to content

Commit a1403ce

Browse files
committed
libsql-sqlite: Document WAL API extension
1 parent cfd549b commit a1403ce

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

libsql-sqlite3/doc/libsql_extensions.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,32 @@ static sqlite3_module helloModule = {
355355
.xPreparedSql = helloPreparedSql,
356356
};
357357
```
358+
359+
## WAL API
360+
361+
The libSQL has the following WAL API functions, which are useful for
362+
syncing the WAL between databases:
363+
364+
* `libsql_wal_disable_checkpoint` -- Disable checkpointing, including on database close.
365+
* `libsql_wal_frame_count` -- Get the number of frames in the WAL.
366+
* `libsql_wal_get_frame` -- Get a frame from the WAL.
367+
* `libsql_wal_insert_begin` -- Begin WAL insertion.
368+
* `libsql_wal_insert_frame` -- Insert a frame into the WAL.
369+
* `libsql_wal_insert_end` -- End WAL insertion.
370+
371+
Example usage:
372+
373+
```c
374+
static void sync_db(sqlite3 *db_primary, sqlite3 *db_backup){
375+
unsigned int max_frame;
376+
377+
libsql_wal_frame_count(db_primary, &max_frame);
378+
libsql_wal_begin_commit(db_backup);
379+
for(int i=1; i<=max_frame; i++){
380+
char frame[4096+24];
381+
libsql_wal_get_frame(db_primary, i, frame, sizeof(frame));
382+
libsql_wal_insert_frame(db_backup, i, frame, sizeof(frame));
383+
}
384+
libsql_wal_end_commit(db_backup);
385+
}
386+
```

0 commit comments

Comments
 (0)