pub struct Client<T = HttpTransport> { /* private fields */ }Expand description
Configured client used to open Circle-backed SQLite databases.
Implementations§
Source§impl Client<HttpTransport>
impl Client<HttpTransport>
Sourcepub fn from_default_config() -> Result<Self>
pub fn from_default_config() -> Result<Self>
Load the default local config and construct a client with the HTTP transport.
This is fallible because it reads the configured octra-sqlite config
file. Use Client::with_options when construction should be purely
in-memory.
Examples found in repository?
examples/remilia-read-api/main.rs (line 15)
12fn main() -> AppResult<()> {
13 let addr = env::var("OCTRA_SQLITE_API_ADDR").unwrap_or_else(|_| "127.0.0.1:8787".to_string());
14 let database_name = env::var("OCTRA_SQLITE_DATABASE").unwrap_or_else(|_| "remilia".to_string());
15 let client = Client::from_default_config()?;
16 let database = client.database(database_name.clone())?;
17 let listener = TcpListener::bind(&addr)?;
18
19 eprintln!("listening on http://{addr}");
20 eprintln!("try: curl http://{addr}/collections/milady");
21
22 for stream in listener.incoming() {
23 match stream {
24 Ok(stream) => {
25 if let Err(error) = handle_connection(stream, &database, &database_name) {
26 eprintln!("request error: {error}");
27 }
28 }
29 Err(error) => eprintln!("accept error: {error}"),
30 }
31 }
32
33 Ok(())
34}Sourcepub fn with_options(options: ClientOptions) -> Self
pub fn with_options(options: ClientOptions) -> Self
Construct a client from explicit options using the default HTTP transport.
Source§impl<T: Transport> Client<T>
impl<T: Transport> Client<T>
Sourcepub fn with_transport(options: ClientOptions, transport: T) -> Self
pub fn with_transport(options: ClientOptions, transport: T) -> Self
Construct a client from explicit options and a custom transport.
Sourcepub fn database(&self, target: impl Into<String>) -> Result<Database<T>>
pub fn database(&self, target: impl Into<String>) -> Result<Database<T>>
Open a database by saved name, Circle ID, or oct:// URI.
Examples found in repository?
examples/remilia-read-api/main.rs (line 16)
12fn main() -> AppResult<()> {
13 let addr = env::var("OCTRA_SQLITE_API_ADDR").unwrap_or_else(|_| "127.0.0.1:8787".to_string());
14 let database_name = env::var("OCTRA_SQLITE_DATABASE").unwrap_or_else(|_| "remilia".to_string());
15 let client = Client::from_default_config()?;
16 let database = client.database(database_name.clone())?;
17 let listener = TcpListener::bind(&addr)?;
18
19 eprintln!("listening on http://{addr}");
20 eprintln!("try: curl http://{addr}/collections/milady");
21
22 for stream in listener.incoming() {
23 match stream {
24 Ok(stream) => {
25 if let Err(error) = handle_connection(stream, &database, &database_name) {
26 eprintln!("request error: {error}");
27 }
28 }
29 Err(error) => eprintln!("accept error: {error}"),
30 }
31 }
32
33 Ok(())
34}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Client<T>
impl<T> RefUnwindSafe for Client<T>where
T: RefUnwindSafe,
impl<T> Send for Client<T>
impl<T> Sync for Client<T>
impl<T> Unpin for Client<T>
impl<T> UnsafeUnpin for Client<T>
impl<T> UnwindSafe for Client<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more