Hello Zig community! ![]()
I’ve been working on a small library in my free time and I’m excited to share the first version of DDB.zig with you.
DDB stands for a simple way to manage structured data in your Zig applications. It’s not a full-fledged SQL database, but rather a lightweight, embedded library that provides a basic set of tools to persist and load your Zig structs with minimal boilerplate.
Think of it as a simple, file-based document store for Zig.
Key Features
- Simple API: Designed to be intuitive for Zig developers. You work directly with your structs.
- Schema based on Zig types: Define your data once as a Zig
struct– the table schema is derived from it. - Easy integration: Can be added to your project with a single
zig fetchcommand. - Currently supports: Linux and macOS (Zig version
0.15.1).
How to Install
Add it to your project:
zig fetch --save https://github.com/Neon32eeee/DDB.zig/archive/refs/heads/main.tar.gz
Then import the module in your build.zig (a full example is in the README).
Quick Example
Here’s a glimpse of how it works:
const std = @import("std");
const ddb = @import("ddb");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var db = try ddb.DB().init("my_app_data", allocator);
defer db.deinit();
const Player = struct {
hp: i32,
name: []const u8,
score: i32,
};
try db.createTable("players", Player);
const players_table = db.getTable("players").?;
const player1 = Player{ .hp = 100, .name = "Jon", .score = 100 };
const element = try ddb.Adapter.toElement(player1, allocator);
try players_table.append(element);
try db.save();
}
This creates a database file, defines a “players” table, and appends a new player entry.
Why DDB?
I wanted something even simpler than SQLite for small tools, game prototypes, or applications where I just need to save and load state without writing a single query. If you’ve ever needed to persist a few structs and found setting up a full database engine to be overkill, DDB might be for you.
Links & Feedback
- GitHub Repository: github.com/Neon32eeee/DDB.zig
- Documentation: More details are available in the project’s Wiki.
This is a very early release (my first Zig library!), and I’m looking for feedback, ideas, and contributors. What features would you like to see? (Querying? Indexes? Better error handling?) Feel free to open an issue or start a discussion here!
Thanks for checking it out! ![]()