Skip to content
Open
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
7 changes: 7 additions & 0 deletions bindings/c/include/libsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ typedef struct libsql_stmt libsql_stmt;

typedef const libsql_database *libsql_database_t;

typedef struct {
int frame_no;
int frames_synced;
} replicated;

typedef struct {
const char *db_path;
const char *primary_url;
Expand Down Expand Up @@ -58,6 +63,8 @@ extern "C" {

int libsql_sync(libsql_database_t db, const char **out_err_msg);

int libsql_sync2(libsql_database_t db, replicated *out_replicated, const char **out_err_msg);

int libsql_open_sync(const char *db_path,
const char *primary_url,
const char *auth_token,
Expand Down
22 changes: 21 additions & 1 deletion bindings/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::runtime::Runtime;
use types::{
blob, libsql_connection, libsql_connection_t, libsql_database, libsql_database_t, libsql_row,
libsql_row_t, libsql_rows, libsql_rows_future_t, libsql_rows_t, libsql_stmt, libsql_stmt_t,
stmt,
replicated, stmt,
};

lazy_static! {
Expand Down Expand Up @@ -46,6 +46,26 @@ pub unsafe extern "C" fn libsql_sync(
}
}

#[no_mangle]
pub unsafe extern "C" fn libsql_sync2(
db: libsql_database_t,
out_replicated: *mut replicated,
out_err_msg: *mut *const std::ffi::c_char,
) -> std::ffi::c_int {
let db = db.get_ref();
match RT.block_on(db.sync()) {
Ok(replicated) => {
(*out_replicated).frame_no = replicated.frame_no().unwrap_or(0) as i32;
(*out_replicated).frames_synced = replicated.frames_synced() as i32;
0
}
Err(e) => {
set_err_msg(format!("Error syncing database: {e}"), out_err_msg);
1
}
}
}

#[no_mangle]
pub unsafe extern "C" fn libsql_open_sync(
db_path: *const std::ffi::c_char,
Expand Down
6 changes: 6 additions & 0 deletions bindings/c/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ impl From<&mut libsql_connection> for libsql_connection_t {
}
}

#[repr(C)]
pub struct replicated {
pub frame_no: std::ffi::c_int,
pub frames_synced: std::ffi::c_int,
}

pub struct stmt {
pub stmt: libsql::Statement,
pub params: Vec<libsql::Value>,
Expand Down