Skip to content

Commit

Permalink
add thread mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Apr 30, 2024
1 parent 250ca1f commit aaaaa9a
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 264 deletions.
43 changes: 2 additions & 41 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#+TITLE: Zig-rocksdb
#+DATE: 2024-04-27T11:27:04+0800
#+LASTMOD: 2024-04-29T22:39:50+0800
#+LASTMOD: 2024-04-30T09:05:31+0800
#+AUTHOR: Jiacai Liu

[[https://github.com/jiacai2050/zig-rocksdb/actions/workflows/CI.yml][https://github.com/jiacai2050/zig-rocksdb/actions/workflows/CI.yml/badge.svg]]
Expand All @@ -12,46 +12,7 @@
zig fetch --save=rocksdb https://github.com/jiacai2050/zig-rocksdb/archive/${COMMIT}.tar.gz
#+end_src

#+begin_src bash :results code :exports results :wrap src zig
cat examples/basic.zig
#+end_src

#+RESULTS:
#+begin_src zig
const std = @import("std");
const rocksdb = @import("rocksdb");

pub fn main() !void {
const allocator = std.heap.page_allocator;
var db = try rocksdb.DB.open(
allocator,
"/tmp/zig-rocksdb-basic",
.{
.create_if_missing = true,
},
);
defer db.deinit();

for (0..10) |i| {
const key = try std.fmt.allocPrint(allocator, "key-{d}", .{i});
defer allocator.free(key);
const value = try std.fmt.allocPrint(allocator, "{d}", .{i * i});
defer allocator.free(value);
try db.put(key, value, .{});
}

for (0..10) |i| {
const key = try std.fmt.allocPrint(allocator, "key-{d}", .{i});
defer allocator.free(key);
const value = try db.get(key, .{});
if (value) |v| {
defer rocksdb.free(v);
std.debug.print("{s} = {s}\n", .{ key, v });
}
}
}
#+end_src

See [[file:examples/basic.zig]], [[file:examples/cf.zig]] for details.
* Other bindings
https://github.com/facebook/rocksdb/blob/main/LANGUAGE-BINDINGS.md

Expand Down
2 changes: 1 addition & 1 deletion examples/basic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const rocksdb = @import("rocksdb");

pub fn main() !void {
const allocator = std.heap.page_allocator;
var db = try rocksdb.DB.open(
var db = try rocksdb.Database(.Single).open(
allocator,
"/tmp/zig-rocksdb-basic",
.{
Expand Down
7 changes: 3 additions & 4 deletions examples/cf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ const rocksdb = @import("rocksdb");
pub fn main() !void {
const allocator = std.heap.page_allocator;

var db = try rocksdb.DB.openColumnFamilies(
var db = try rocksdb.Database(.Multiple).openColumnFamilies(
allocator,
"/tmp/zig-rocksdb-cf",
.{
.create_if_missing = true,
},
.{ .create_if_missing = true },
.{},
);
defer db.deinit();

Expand Down
Loading

0 comments on commit aaaaa9a

Please sign in to comment.