Skip to content
Merged
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
8 changes: 6 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
path: dist

macos-x86_64:
runs-on: macos-latest
runs-on: macos-13
strategy:
matrix:
target: [x86_64]
Expand All @@ -59,12 +59,16 @@ jobs:
path: dist

macos-arm64:
runs-on: macos-arm64
runs-on: macos-13-xlarge
strategy:
matrix:
target: [aarch64]
steps:
- uses: actions/checkout@v3
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.14
with:
cmake-version: '3.18.x'
- uses: actions/setup-python@v4
with:
python-version: '3.10'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.19.0"
libsql = { version = "0.3.0" }
libsql = { version = "0.3.0", features = ["encryption"] }
tokio = { version = "1.29.1", features = [ "rt-multi-thread" ] }
tracing-subscriber = "0.3"
28 changes: 24 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,59 @@ fn is_remote_path(path: &str) -> bool {
}

#[pyfunction]
#[pyo3(signature = (database, isolation_level="DEFERRED".to_string(), check_same_thread=true, uri=false, sync_url=None, auth_token=""))]
#[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))]
fn connect(
py: Python<'_>,
database: String,
isolation_level: Option<String>,
check_same_thread: bool,
uri: bool,
sync_url: Option<String>,
sync_interval: Option<f64>,
auth_token: &str,
encryption_key: Option<String>,
) -> PyResult<Connection> {
let ver = env!("CARGO_PKG_VERSION");
let ver = format!("libsql-python-rpc-{ver}");
let rt = tokio::runtime::Runtime::new().unwrap();
let encryption_config = match encryption_key {
Some(key) => {
let cipher = libsql::Cipher::default();
let encryption_config = libsql::EncryptionConfig::new(cipher, key.into());
Some(encryption_config)
}
None => None,
};
let db = if is_remote_path(&database) {
let result = libsql::Database::open_remote_internal(database.clone(), auth_token, ver);
result.map_err(to_py_err)?
} else {
match sync_url {
Some(sync_url) => {
let sync_interval = sync_interval.map(|i| std::time::Duration::from_secs_f64(i));
let fut = libsql::Database::open_with_remote_sync_internal(
database,
sync_url,
auth_token,
Some(ver),
true,
None,
None,
encryption_config,
sync_interval,
);
tokio::pin!(fut);
let result = rt.block_on(check_signals(py, fut));
result.map_err(to_py_err)?
}
None => libsql_core::Database::open(database).map_err(to_py_err)?,
None => {
let mut builder = libsql::Builder::new_local(database);
if let Some(config) = encryption_config {
builder = builder.encryption_config(config);
}
let fut = builder.build();
tokio::pin!(fut);
let result = rt.block_on(check_signals(py, fut));
result.map_err(to_py_err)?
}
}
};
let autocommit = isolation_level.is_none();
Expand Down