Skip to content

Commit b688913

Browse files
committed
bindings/c: Add offline to config struct
Make it possible to configure offline writes via the normal `libsql_config` struct too.
1 parent 8b3c9a7 commit b688913

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

bindings/c/include/libsql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct {
4040
const char *encryption_key;
4141
int sync_interval;
4242
char with_webpki;
43+
char offline;
4344
} libsql_config;
4445

4546
typedef const libsql_connection *libsql_connection_t;

bindings/c/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub unsafe extern "C" fn libsql_open_sync(
9797
encryption_key,
9898
sync_interval: 0,
9999
with_webpki: 0,
100+
offline: 0,
100101
};
101102
libsql_open_sync_with_config(config, out_db, out_err_msg)
102103
}
@@ -119,6 +120,7 @@ pub unsafe extern "C" fn libsql_open_sync_with_webpki(
119120
encryption_key,
120121
sync_interval: 0,
121122
with_webpki: 1,
123+
offline: 0,
122124
};
123125
libsql_open_sync_with_config(config, out_db, out_err_msg)
124126
}
@@ -256,7 +258,9 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
256258
return 100;
257259
}
258260
};
259-
if let Some(primary_url) = primary_url_with_offline_removed {
261+
let offline = config.offline != 0 || primary_url_with_offline_removed.is_some();
262+
if offline {
263+
let primary_url = primary_url_with_offline_removed.unwrap_or(primary_url.to_owned());
260264
let mut builder =
261265
Builder::new_synced_database(db_path, primary_url.to_owned(), auth_token.to_owned());
262266
if config.with_webpki != 0 {

bindings/c/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct libsql_config {
1414
pub encryption_key: *const std::ffi::c_char,
1515
pub sync_interval: std::ffi::c_int,
1616
pub with_webpki: std::ffi::c_char,
17+
pub offline: std::ffi::c_char,
1718
}
1819

1920
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)