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: StringThe connection URI for the database server.
config: DatabaseConfigDatabase configuration
encryption_key: Option<EncryptionKey>Encryption key for data protection
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
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.
Sourcepub fn with_uri(uri: &str) -> Self
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.
Sourcepub fn with_storage_path<P: AsRef<Path>>(uri: &str, path: P) -> Self
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.
Sourcepub fn with_config(config: DatabaseConfig) -> Result<Self>
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.
Sourcepub fn with_config_file<P: AsRef<Path>>(config_path: P) -> Result<Self>
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 readDbError::TomlError- If the file contains invalid TOMLDbError::ValidationError- If the configuration is invalid
Sourcepub fn with_encryption<S: Into<String>>(self, password: S) -> Result<Self>
pub fn with_encryption<S: Into<String>>(self, password: S) -> Result<Self>
Sourcepub fn list_database_names(&self) -> Vec<String>
pub fn list_database_names(&self) -> Vec<String>
Sourcepub fn drop_database(&mut self, name: &str) -> Result<()>
pub fn drop_database(&mut self, name: &str) -> Result<()>
Sourcepub fn save(&self) -> Result<()>
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.
Sourcepub fn load(&mut self) -> Result<()>
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.
Sourcepub fn config(&self) -> &DatabaseConfig
pub fn config(&self) -> &DatabaseConfig
Get configuration reference
Sourcepub fn update_config(&mut self, config: DatabaseConfig) -> Result<()>
pub fn update_config(&mut self, config: DatabaseConfig) -> Result<()>
Update configuration