Skip to content

Configuration

TaiDB configuration is represented by Options and convenience methods on EngineConfig.

let db = taidb::EngineConfig::new("./app.taidb")
.zstd_fast()
.mmap_reads(true)
.open()?;

Available shortcuts:

MethodEffect
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.

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 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.

ModeWrite behavior
Durability::BufferedWrite to the file handle and let the OS flush later.
Durability::FlushCall flush() after each appended record or batch.
Durability::SyncCall 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.

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.

use taidb::Options;
let options = Options::builder().zstd(3, 256).build();

Compression is most useful for larger values and text-heavy data.

use taidb::{EncryptionKey, Options};
let key = EncryptionKey::load_hex_file("./taidb.key")?;
let options = Options::builder().encryption_key(key).build();

The CLI equivalent:

Terminal window
taidb --key-file ./taidb.key put ./secure.taidb key value
let db = taidb::EngineConfig::new("./app.taidb")
.mmap_reads(false)
.open()?;

Disable mmap reads only when your environment or filesystem behavior requires direct reads.