mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-06-02 17:22:50 +00:00
Merge pull request #1629 from tursodatabase/lucio/update-c-bindings
c: add replicated data for sync
This commit is contained in:
@ -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;
|
||||
@ -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,
|
||||
|
@ -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! {
|
||||
@ -46,6 +46,29 @@ 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) => {
|
||||
if !out_replicated.is_null() {
|
||||
(*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,
|
||||
|
@ -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>,
|
||||
|
Reference in New Issue
Block a user