Skip to content

Commit 08530bf

Browse files
committed
c: add replicated data for sync
This adds a new replicated struct that is output during sync for the C bindings.
1 parent f0d6611 commit 08530bf

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

bindings/c/include/libsql.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ typedef struct libsql_stmt libsql_stmt;
2727

2828
typedef const libsql_database *libsql_database_t;
2929

30+
typedef struct {
31+
uintptr_t frame_no;
32+
uintptr_t frames_synced;
33+
} replicated;
34+
3035
typedef struct {
3136
const char *db_path;
3237
const char *primary_url;
@@ -56,7 +61,7 @@ typedef struct {
5661
extern "C" {
5762
#endif // __cplusplus
5863

59-
int libsql_sync(libsql_database_t db, const char **out_err_msg);
64+
int libsql_sync(libsql_database_t db, replicated *out_replicated, const char **out_err_msg);
6065

6166
int libsql_open_sync(const char *db_path,
6267
const char *primary_url,

bindings/c/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tokio::runtime::Runtime;
1111
use types::{
1212
blob, libsql_connection, libsql_connection_t, libsql_database, libsql_database_t, libsql_row,
1313
libsql_row_t, libsql_rows, libsql_rows_future_t, libsql_rows_t, libsql_stmt, libsql_stmt_t,
14-
stmt,
14+
replicated, stmt,
1515
};
1616

1717
lazy_static! {
@@ -34,11 +34,16 @@ unsafe fn set_err_msg(msg: String, output: *mut *const std::ffi::c_char) {
3434
#[no_mangle]
3535
pub unsafe extern "C" fn libsql_sync(
3636
db: libsql_database_t,
37+
out_replicated: *mut replicated,
3738
out_err_msg: *mut *const std::ffi::c_char,
3839
) -> std::ffi::c_int {
3940
let db = db.get_ref();
4041
match RT.block_on(db.sync()) {
41-
Ok(_) => 0,
42+
Ok(replicated) => {
43+
(*out_replicated).frame_no = replicated.frame_no().unwrap_or(0) as usize;
44+
(*out_replicated).frames_synced = replicated.frames_synced() as usize;
45+
0
46+
}
4247
Err(e) => {
4348
set_err_msg(format!("Error syncing database: {e}"), out_err_msg);
4449
1

bindings/c/src/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ impl From<&mut libsql_connection> for libsql_connection_t {
115115
}
116116
}
117117

118+
#[repr(C)]
119+
pub struct replicated {
120+
pub frame_no: usize,
121+
pub frames_synced: usize,
122+
}
123+
118124
pub struct stmt {
119125
pub stmt: libsql::Statement,
120126
pub params: Vec<libsql::Value>,

0 commit comments

Comments
 (0)