Client

Struct Client 

Source
pub struct Client {
    pub databases: HashMap<String, Database>,
    pub uri: String,
    pub config: DatabaseConfig,
    pub encryption_key: Option<EncryptionKey>,
}
Expand description

The main entry point for interacting with LuckDB databases.

The Client struct is responsible for managing databases and providing access to them. It also handles persistence operations like saving and loading data to disk.

§Example

use luckdb::Client;

// Create a new client with a storage path
let mut client = Client::with_storage_path("mongodb://localhost", "/path/to/data");

// Access or create a database
let db = client.db("mydatabase");

// Save changes to disk
client.save().unwrap();

Fields§

§databases: HashMap<String, Database>

The databases managed by this client, indexed by name.

§uri: String

The connection URI for the database server.

§config: DatabaseConfig

Database configuration

§encryption_key: Option<EncryptionKey>

Encryption key for data protection

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Creates a new client with default settings.

Uses the default configuration with in-memory storage and no encryption. This is suitable for testing and temporary data storage.

§Examples
use luckdb::Client;

let mut client = Client::new();
let db = client.db("test");
§Note

Data stored in-memory will be lost when the client is dropped. Use with_config() or with_storage_path() for persistent storage.

Source

pub fn with_uri(uri: &str) -> Self

Creates a new client with a custom connection URI.

§Arguments
  • uri - The connection URI for the database server.
Source

pub fn with_storage_path<P: AsRef<Path>>(uri: &str, path: P) -> Self

Creates a new client with a custom connection URI and storage path.

§Arguments
  • uri - The connection URI for the database server.
  • path - The file path where data will be persisted to disk.
Source

pub fn with_config(config: DatabaseConfig) -> Result<Self>

Creates a new client with the specified configuration.

This method allows you to configure storage, encryption, authentication, and other settings through a DatabaseConfig object.

§Arguments
  • config - Database configuration object
§Returns

Returns a Result<Client> which will be an error if the configuration validation fails.

§Examples
use luckdb::{Client, config::DatabaseConfig};

// Create configuration with storage and encryption
let config = DatabaseConfig::with_storage_path("./data")
    .with_encryption("secure_password");

let mut client = Client::with_config(config)?;
let db = client.db("mydb");
§Errors

Returns DbError::ValidationError if the configuration is invalid.

Source

pub fn with_config_file<P: AsRef<Path>>(config_path: P) -> Result<Self>

Creates a new client by loading configuration from a TOML file.

This is a convenience method that loads configuration from a TOML file and creates a client with that configuration. The file must contain a [luckdb] section with valid configuration parameters.

§Arguments
  • config_path - Path to the TOML configuration file
§Returns

Returns a Result<Client> which will be an error if the file cannot be read, is invalid TOML, or contains invalid configuration.

§Examples
use luckdb::Client;

// Load from config.toml file
let mut client = Client::with_config_file("config.toml")?;
let db = client.db("mydb");
§Configuration File Format
[luckdb]
storage_path = "./data"
encryption_enabled = true
encryption_password = "your_password"
auth_username = "admin"
auth_password = "auth_password"
§Errors
  • DbError::IoError - If the file cannot be read
  • DbError::TomlError - If the file contains invalid TOML
  • DbError::ValidationError - If the configuration is invalid
Source

pub fn with_encryption<S: Into<String>>(self, password: S) -> Result<Self>

Enable encryption with a password.

§Arguments
  • password - Password for encryption key derivation.
Source

pub fn db(&mut self, name: &str) -> &mut Database

Gets a database by name, creating it if it doesn’t exist.

§Arguments
  • name - The name of the database to access.
§Returns

A mutable reference to the database.

Source

pub fn list_database_names(&self) -> Vec<String>

Lists the names of all databases managed by this client.

§Returns

A list of database names.

Source

pub fn drop_database(&mut self, name: &str) -> Result<()>

Drops a database managed by this client.

§Arguments
  • name - The name of the database to drop.
§Errors

Returns an error if the database does not exist.

Source

pub fn uri(&self) -> &str

Gets the connection URI used by this client.

§Returns

A reference to the connection URI string.

Source

pub fn save(&self) -> Result<()>

Saves all data to disk at the configured storage path.

§Errors

Returns an error if no storage path is configured or if there’s an IO error.

Source

pub fn load(&mut self) -> Result<()>

Loads all data from disk at the configured storage path.

§Errors

Returns an error if no storage path is configured or if there’s an IO or deserialization error.

Source

pub fn config(&self) -> &DatabaseConfig

Get configuration reference

Source

pub fn update_config(&mut self, config: DatabaseConfig) -> Result<()>

Update configuration

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V