Embedded bi-temporal graph database — C header + prebuilt shared library
Minigraf for C and any language with a C FFI. Distributed as platform tarballs containing minigraf.h and prebuilt shared and static libraries.
Download the platform tarball from GitHub Releases:
# Linux x86_64 example
curl -L https://github.com/project-minigraf/minigraf/releases/download/v1.0.0/minigraf-c-v1.0.0-x86_64-unknown-linux-gnu.tar.gz | tar xzEach archive contains:
include/minigraf.h— stable C header (cbindgen-generated)lib/libminigraf_c.so(Linux) /libminigraf_c.dylib(macOS) /minigraf_c.dll(Windows)lib/libminigraf_c.a(Linux/macOS) /minigraf_c.lib(Windows)
#include "minigraf.h"
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *err = NULL;
MiniGrafDb *db = minigraf_open("myapp.graph", &err);
if (!db) { fprintf(stderr, "open: %s\n", err); free(err); return 1; }
char *result = minigraf_execute(
db,
"(transact [[:alice :person/name \"Alice\"] [:alice :person/age 30]])",
&err
);
if (!result) { fprintf(stderr, "execute: %s\n", err); free(err); }
else { printf("%s\n", result); minigraf_string_free(result); }
result = minigraf_execute(
db,
"(query [:find ?name :where [?e :person/name ?name]])",
&err
);
if (!result) { fprintf(stderr, "execute: %s\n", err); free(err); }
else { printf("%s\n", result); minigraf_string_free(result); }
minigraf_checkpoint(db, NULL);
minigraf_close(db);
return 0;
}Mirrors SQLite:
minigraf_open— caller owns theMiniGrafDb*; free withminigraf_closeminigraf_execute— returns a heap-allocated JSON string; caller must free withminigraf_string_free- Error strings (
char **errout-param) are heap-allocated; caller frees withfree()
| Function | Description |
|---|---|
minigraf_open(path, err) |
Open or create a file-backed database |
minigraf_open_in_memory(err) |
Open an in-memory database |
minigraf_execute(db, datalog, err) |
Execute a Datalog command; returns JSON string |
minigraf_string_free(s) |
Free a string returned by minigraf_execute |
minigraf_checkpoint(db, err) |
Flush dirty pages to disk |
minigraf_close(db) |
Close the database |
minigraf_last_error() |
Get the last error message (thread-local) |
See include/minigraf.h for the complete API.
MIT OR Apache-2.0