Skip to content

Options

The Options struct configures database behavior at open time.

All Fields

zig
const options = zkv.Options{
    .path = "data.zkv",               // Database file path
    .create_if_missing = true,         // Create file if it doesn't exist
    .read_only = false,                // Open in read only mode
    .page_size = 4096,                 // Page size in bytes
    .max_key_size = 1024,              // Max key length in bytes
    .max_value_size = 1024 * 1024,     // Max value length (1 MB)
    .cache_size_bytes = 1024 * 1024,   // Cache size (1 MB)
    .checksum = .crc32c,               // Checksum algorithm
    .compression = .none,              // Compression algorithm
    .wal_enabled = true,               // Enable write ahead log
};

Field Reference

FieldTypeDefaultDescription
path[]const u8"data.zkv"File path for the database
create_if_missingbooltrueCreate the file on open if absent
read_onlyboolfalseDisallow writes when true
page_sizeu324096Storage page size in bytes
max_key_sizeusize1024Maximum allowed key length
max_value_sizeusize1048576Maximum allowed value length
cache_size_bytesusize1048576In memory cache budget
checksumChecksumKind.crc32cIntegrity checksum algorithm
compressionCompression.noneValue compression codec
wal_enabledbooltrueWrite ahead log for durability

IMPORTANT

The write ahead log (WAL) ensures durability. Disable only if you can afford to lose recent writes.

Compression Formats

FormatDescription
.noneNo compression (default, fastest)
.zstdZstandard — high ratio, fast (external dep)
.brotliBrotli — excellent ratio (external dep)
.gzipgzip — widely compatible (stdlib)
.lzmaLZMA — high ratio, slower (stdlib, decompress only)
.xzXZ — high ratio (stdlib, decompress only)

NOTE

Compression works automatically on all reads/writes. The format is detected from metadata when reopening a database.

Checksum Algorithms

AlgorithmDescription
.crc32cCRC32C — hardware accelerated on x86_64
.xxhashxxHash — fast non cryptographic hash

Export/Import Options

zig
// ExportOptions
.{
    .format = .raw_snapshot,  // .raw_snapshot, .jsonl, or .csv
}

// ImportOptions
.{
    .format = .raw_snapshot,  // .raw_snapshot, .jsonl, or .csv
}

SearchOptions

zig
.{
    .prefix = "user:",        // Filter by key prefix
    .limit = 100,             // Max results
    .offset = 0,              // Skip first N results
    .from = null,             // Range start (inclusive)
    .to = null,               // Range end (exclusive)
}

SortOptions

zig
.{
    .limit = 50,              // Max results after sorting
}

FilterOptions

zig
.{
    .limit = 100,             // Max results
    .offset = 0,              // Skip first N
}

Released under the MIT License.