Skip to content

Commit e4784d7

Browse files
committed
Make it possible to provide custom connector to SyncedDatabase
Signed-off-by: Piotr Jastrzebski <[email protected]>
1 parent 9547648 commit e4784d7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

libsql/src/database/builder.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cfg_core! {
22
use crate::EncryptionConfig;
33
}
4+
45
use crate::{Database, Result};
56

67
use super::DbType;
@@ -99,6 +100,7 @@ impl Builder<()> {
99100
connector: None,
100101
version: None,
101102
},
103+
connector:None,
102104
},
103105
}
104106
}
@@ -399,6 +401,7 @@ cfg_sync! {
399401
path: std::path::PathBuf,
400402
flags: crate::OpenFlags,
401403
remote: Remote,
404+
connector: Option<crate::util::ConnectorService>,
402405
}
403406

404407
impl Builder<SyncedDatabase> {
@@ -408,6 +411,18 @@ cfg_sync! {
408411
self
409412
}
410413

414+
/// Provide a custom http connector that will be used to create http connections.
415+
pub fn connector<C>(mut self, connector: C) -> Builder<SyncedDatabase>
416+
where
417+
C: tower::Service<http::Uri> + Send + Clone + Sync + 'static,
418+
C::Response: crate::util::Socket,
419+
C::Future: Send + 'static,
420+
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
421+
{
422+
self.inner.connector = Some(wrap_connector(connector));
423+
self
424+
}
425+
411426
/// Build a connection to a local database that can be synced to remote server.
412427
pub async fn build(self) -> Result<Database> {
413428
let SyncedDatabase {
@@ -420,11 +435,16 @@ cfg_sync! {
420435
connector: _,
421436
version: _,
422437
},
438+
connector,
423439
} = self.inner;
424440

425441
let path = path.to_str().ok_or(crate::Error::InvalidUTF8Path)?.to_owned();
426442

427-
let https = super::connector()?;
443+
let https = if let Some(connector) = connector {
444+
connector
445+
} else {
446+
wrap_connector(super::connector()?)
447+
};
428448
use tower::ServiceExt;
429449

430450
let svc = https

0 commit comments

Comments
 (0)