Skip to content

Commit b3b3c24

Browse files
authored
Merge pull request #40 from tursodatabase/embedded-replicas
Embedded replica improvements
2 parents 738fddc + d748b90 commit b3b3c24

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

.github/workflows/CI.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
path: dist
3838

3939
macos-x86_64:
40-
runs-on: macos-latest
40+
runs-on: macos-13
4141
strategy:
4242
matrix:
4343
target: [x86_64]
@@ -59,12 +59,16 @@ jobs:
5959
path: dist
6060

6161
macos-arm64:
62-
runs-on: macos-arm64
62+
runs-on: macos-13-xlarge
6363
strategy:
6464
matrix:
6565
target: [aarch64]
6666
steps:
6767
- uses: actions/checkout@v3
68+
- name: Setup cmake
69+
uses: jwlawson/actions-setup-cmake@v1.14
70+
with:
71+
cmake-version: '3.18.x'
6872
- uses: actions/setup-python@v4
6973
with:
7074
python-version: '3.10'

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ crate-type = ["cdylib"]
99

1010
[dependencies]
1111
pyo3 = "0.19.0"
12-
libsql = { version = "0.3.0" }
12+
libsql = { version = "0.3.0", features = ["encryption"] }
1313
tokio = { version = "1.29.1", features = [ "rt-multi-thread" ] }
1414
tracing-subscriber = "0.3"

src/lib.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,59 @@ fn is_remote_path(path: &str) -> bool {
1919
}
2020

2121
#[pyfunction]
22-
#[pyo3(signature = (database, isolation_level="DEFERRED".to_string(), check_same_thread=true, uri=false, sync_url=None, auth_token=""))]
22+
#[pyo3(signature = (database, isolation_level="DEFERRED".to_string(), check_same_thread=true, uri=false, sync_url=None, sync_interval=None, auth_token="", encryption_key=None))]
2323
fn connect(
2424
py: Python<'_>,
2525
database: String,
2626
isolation_level: Option<String>,
2727
check_same_thread: bool,
2828
uri: bool,
2929
sync_url: Option<String>,
30+
sync_interval: Option<f64>,
3031
auth_token: &str,
32+
encryption_key: Option<String>,
3133
) -> PyResult<Connection> {
3234
let ver = env!("CARGO_PKG_VERSION");
3335
let ver = format!("libsql-python-rpc-{ver}");
3436
let rt = tokio::runtime::Runtime::new().unwrap();
37+
let encryption_config = match encryption_key {
38+
Some(key) => {
39+
let cipher = libsql::Cipher::default();
40+
let encryption_config = libsql::EncryptionConfig::new(cipher, key.into());
41+
Some(encryption_config)
42+
}
43+
None => None,
44+
};
3545
let db = if is_remote_path(&database) {
3646
let result = libsql::Database::open_remote_internal(database.clone(), auth_token, ver);
3747
result.map_err(to_py_err)?
3848
} else {
3949
match sync_url {
4050
Some(sync_url) => {
51+
let sync_interval = sync_interval.map(|i| std::time::Duration::from_secs_f64(i));
4152
let fut = libsql::Database::open_with_remote_sync_internal(
4253
database,
4354
sync_url,
4455
auth_token,
4556
Some(ver),
4657
true,
47-
None,
48-
None,
58+
encryption_config,
59+
sync_interval,
4960
);
5061
tokio::pin!(fut);
5162
let result = rt.block_on(check_signals(py, fut));
5263
result.map_err(to_py_err)?
5364
}
54-
None => libsql_core::Database::open(database).map_err(to_py_err)?,
65+
None => {
66+
let mut builder = libsql::Builder::new_local(database);
67+
if let Some(config) = encryption_config {
68+
builder = builder.encryption_config(config);
69+
}
70+
let fut = builder.build();
71+
tokio::pin!(fut);
72+
let result = rt.block_on(check_signals(py, fut));
73+
result.map_err(to_py_err)?
74+
}
5575
}
5676
};
5777
let autocommit = isolation_level.is_none();

0 commit comments

Comments
 (0)