Configuration
TaiDB configuration is represented by Options and convenience methods on
EngineConfig.
EngineConfig shortcuts
Section titled “EngineConfig shortcuts”let db = taidb::EngineConfig::new("./app.taidb") .zstd_fast() .mmap_reads(true) .open()?;Available shortcuts:
| Method | Effect |
|---|---|
durability(mode) | Set write durability mode. |
mmap_reads(enabled) | Enable or disable mmap reads. |
compression(mode) | Set explicit compression. |
zstd_fast() | zstd level 1, practical default. |
zstd_dense() | zstd level 19, smaller but slower. |
read_only() | Open an existing database without write/create access. |
read_write() | Return to the default writable open mode. |
configure(builder) | Modify options with OptionsBuilder. |
options(options) | Replace all options. |
Options builder
Section titled “Options builder”Use Options::builder() when you want one readable setup block that can be
shared between TaiDb and TaiDbEngine.
use taidb::{EngineConfig, Options};
let options = Options::builder() .flush() .mmap_reads(true) .zstd_fast() .build();
let db = EngineConfig::new("./app.taidb").options(options).open()?;EngineConfig::configure applies the same builder without storing an
intermediate value:
let db = taidb::EngineConfig::new("./app.taidb") .configure(|options| options.flush().zstd_fast()) .open()?;Durability
Section titled “Durability”Durability controls how aggressively writes are flushed.
use taidb::{Durability, EngineConfig};
let db = EngineConfig::new("./app.taidb") .durability(Durability::Sync) .open()?;Use stronger durability when data loss after a crash is unacceptable. Use faster modes only when data is rebuildable or your application has its own recovery strategy.
| Mode | Write behavior |
|---|---|
Durability::Buffered | Write to the file handle and let the OS flush later. |
Durability::Flush | Call flush() after each appended record or batch. |
Durability::Sync | Call sync_data() after each appended record or batch. |
TaiDb::flush() always performs a full flush() plus sync_data() on writable
handles. On read-only handles it is a no-op so snapshot and verification
workflows can safely share the same helper code.
Read-only opens
Section titled “Read-only opens”Use read-only opens for backup validation, import sources, dashboards, inspection tools, and any workflow that must not create or modify files.
use taidb::EngineConfig;
let mut db = EngineConfig::new("./app.taidb") .read_only() .open()?;
let value = db.get_text("doc:1")?;Lower-level code can call TaiDb::open_read_only or
TaiDb::open_read_only_with_options. Read-only opens require the database file
to already exist. They take a shared file lock and reject write operations with
Error::ReadOnly.
Compression
Section titled “Compression”use taidb::Options;
let options = Options::builder().zstd(3, 256).build();Compression is most useful for larger values and text-heavy data.
Encryption
Section titled “Encryption”use taidb::{EncryptionKey, Options};
let key = EncryptionKey::load_hex_file("./taidb.key")?;let options = Options::builder().encryption_key(key).build();The CLI equivalent:
taidb --key-file ./taidb.key put ./secure.taidb key valuemmap reads
Section titled “mmap reads”let db = taidb::EngineConfig::new("./app.taidb") .mmap_reads(false) .open()?;Disable mmap reads only when your environment or filesystem behavior requires direct reads.