pub struct SyncClient { /* private fields */ }Expand description
A blocking client.
Provides synchronous functions for interacting with the database.
For an asynchronous, non-blocking client, use AsyncClient.
let client = replitdb::SyncClient::new();
client.set("greeting", "hello world")?;
println!("{}", client.get("greeting")?);Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new synchronous client, fetching the URL from an environment variable.
§Panics
Panics if the database URL environment variable (REPLIT_DB_URL) is not set.
Sourcepub fn new_url(url: impl Into<String>) -> Self
pub fn new_url(url: impl Into<String>) -> Self
Create a new synchronous client, specifying a custom database URL.
Sourcepub fn get(&self, key: impl Into<String>) -> Result<Option<String>, String>
pub fn get(&self, key: impl Into<String>) -> Result<Option<String>, String>
Get the value of the specified key. Returns Ok(None) if the key does not exist.
Sourcepub fn set(
&self,
key: impl Into<String>,
value: impl Into<String>,
) -> Result<(), String>
pub fn set( &self, key: impl Into<String>, value: impl Into<String>, ) -> Result<(), String>
Set the value of the specified key to the provided value.
Sourcepub fn delete(&self, key: impl Into<String>) -> Result<(), String>
pub fn delete(&self, key: impl Into<String>) -> Result<(), String>
Delete the specified key from the database.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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