Skip to content

ChainSafe/rocksdb.zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RocksDB.zig

A minimal, idiomatic Zig wrapper around RocksDB's C API.

Installation

  1. Zig fetch
zig fetch --save=rocksdb git+https://github.com/chainsafe/rocksdb.zig
  1. In your build.zig, link the dependency

    const rocksdb_module = b.dependency("rocksdb", .{}).module("rocksdb");
    my_module.addImport("rocksdb", rocksdb_module);
  2. Import and use in your code:

    const rocksdb = @import("rocksdb");

Examples

Basic Operations

Here's a simple example to get you started:

const std = @import("std");
const rocksdb = @import("rocksdb");

pub fn main() !void {
    // Open database
    var db = try rocksdb.Database.open("/tmp/testdb", .{});
    defer db.close();

    // Put a key-value pair
    try db.put("hello", "world");

    // Get the value
    const value = try db.get("hello");
    if (value) |v| {
        std.debug.print("Value: {s}\n", .{v});
        // IMPORTANT: Free the memory allocated by LevelDB
        rocksdb.free(v.ptr);
    }
}

Write Batches

var db = try Database.open(db_path, .{});
defer db.close();

var batch = try WriteBatch.init();
defer batch.deinit();

batch.put("a", "one");
batch.put("b", "two");
try db.write(&batch);

Development

Update rocksdb version

  1. Fetch the latest version via following command.

    zig fetch --save=rocksdb https://github.com/facebook/rocksdb/archive/refs/tags/v10.5.1.zip
  2. Go the errors file and take a look at the error status.

  3. Update the version macros in build.zig

Coding Style

We recommend to use style guide from TigerBeetle

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages