Relational NT
A relational database kernel shaped around NT-style object management.
Loading...
Searching...
No Matches
RNT_C_API.h
Go to the documentation of this file.
1#pragma once
2
34
35#include <stddef.h>
36#include <stdint.h>
37
38#include "Api.h"
39#include "VM.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
46typedef void* rnt_handle_t;
47
49typedef void* rnt_cursor_t;
50
51/* ------------------------------------------------------------------ */
52/* Runtime lifecycle */
53/* ------------------------------------------------------------------ */
54
72NT_API int rnt_init(const char* driver, const char* storage_path);
73
74/* ------------------------------------------------------------------ */
75/* Authentication */
76/* ------------------------------------------------------------------ */
77
86NT_API int rnt_firewall(const char* auth_method, char** claims_out);
87
88/* ------------------------------------------------------------------ */
89/* Session lifecycle */
90/* ------------------------------------------------------------------ */
91
106NT_API int rnt_session_open(void* connection_context, char** session_hash_out);
107
118NT_API int rnt_session_close(const char* session_hash);
119
137NT_API int rnt_session_set_branch(const char* session_hash, const char* branch_name,
138 const char* target_hash);
139
140/* ------------------------------------------------------------------ */
141/* Ephemeral relations */
142/* ------------------------------------------------------------------ */
143
150typedef void* rnt_tuple_sink_t;
151
169typedef int (*rnt_generator_fn)(void* ctx, const char* args, size_t offset, size_t limit,
170 rnt_tuple_sink_t sink);
171
181NT_API int rnt_sink_emit(rnt_tuple_sink_t sink, const char* tuple_kv);
182
220NT_API int rnt_register_ephemeral_relation(const char* session_hash, int named, const char* name,
221 rnt_generator_fn generator, void* generator_ctx,
222 int cardinality, const char* generator_identity,
223 const char* schema_kv, const char* dependencies,
224 char** path_out);
225
237NT_API int rnt_drop_ephemeral_relation(const char* session_hash, const char* name);
238
239/* ------------------------------------------------------------------ */
240/* Handle lifecycle */
241/* ------------------------------------------------------------------ */
242
255NT_API rnt_handle_t rnt_open_handle(const char* path, const char* claims);
256
261NT_API int rnt_close_handle(rnt_handle_t handle);
262
276NT_API int rnt_branch_target(rnt_handle_t handle, char** target_hash_out);
277
298NT_API int rnt_branch_advance(const char* branch_path, const char* new_hash);
299
300/* ------------------------------------------------------------------ */
301/* Object registration */
302/* ------------------------------------------------------------------ */
303
314NT_API int rnt_register_relation(const char* path);
315
330NT_API int rnt_register_branch(const char* path, const char* target_hash);
331
347NT_API int rnt_list_relations(const char* branch_mg_path, char** out);
348
360NT_API int rnt_list_branch_multigroups(const char* branch_path, char** out);
361
374NT_API int rnt_list_snapshot_relations(const char* snapshot_hash, char** out);
375
376/* ------------------------------------------------------------------ */
377/* Tuple storage */
378/* ------------------------------------------------------------------ */
379
394NT_API int rnt_link_tuple(const char* relation_path, const char* kv_attrs, char** hash_out);
395
408NT_API int rnt_unlink_tuple(const char* relation_path, const char* tuple_hash);
409
420NT_API int rnt_clear_relation(const char* relation_path);
421
435NT_API int rnt_relation_root(const char* relation_path, char** root_hash_out);
436
437/* ------------------------------------------------------------------ */
438/* Cursor and VM */
439/* ------------------------------------------------------------------ */
440
452
465NT_API int rnt_cursor_next(rnt_cursor_t cursor, char** tuple_out);
466
471NT_API int rnt_cursor_close(rnt_cursor_t cursor);
472
473/* ------------------------------------------------------------------ */
474/* VM plan builder */
475/* ------------------------------------------------------------------ */
476
478typedef void* rnt_plan_t;
479
486typedef struct {
487 const char* relation_path;
489
496typedef struct {
497 rnt_plan_t left;
498 rnt_plan_t right;
499 const char** attrs;
501
507typedef struct {
508 rnt_plan_t source;
509 size_t limit;
511
519typedef struct {
520 rnt_plan_t source;
521 const char** attrs;
523
534typedef struct {
535 rnt_plan_t source;
537
544
545typedef struct {
546 rnt_plan_t source;
547 const char** pairs;
549
551
552typedef struct {
553 rnt_plan_t *sources;
555
562typedef struct {
563 nt::Operation operation;
564 PlanArgsScan scan;
565 PlanArgsJoin join;
566 PlanArgsTake take;
567 PlanArgsProject project;
568 PlanArgsMaterialize materialize;
569 PlanArgsRename rename;
570 PlanArgsUnion union_;
571} PlanAction;
572
585
593NT_API void rnt_plan_free(rnt_plan_t plan);
594
605
616NT_API int rnt_vm_cursor_next(rnt_cursor_t vm_cursor, char** tuple_out);
617
622NT_API int rnt_vm_cursor_close(rnt_cursor_t vm_cursor);
623
624/* ------------------------------------------------------------------ */
625/* Memory management */
626/* ------------------------------------------------------------------ */
627
629NT_API void rnt_free_string(char* s);
630
632NT_API void rnt_free_bytes(uint8_t* p);
633
634#ifdef __cplusplus
635}
636#endif
Defines symbol visibility for the Relational NT public API.
NT_API rnt_cursor_t rnt_vm_execute_plan(rnt_plan_t plan)
Executes a plan tree and returns a streaming VM cursor.
Definition RNT_C_API.cpp:1251
NT_API void rnt_free_bytes(uint8_t *p)
Releases a byte buffer allocated by the API.
Definition RNT_C_API.cpp:1218
NT_API rnt_handle_t rnt_open_handle(const char *path, const char *claims)
Opens a handle to the object at the given slash-separated path.
Definition RNT_C_API.cpp:926
NT_API int rnt_init(const char *driver, const char *storage_path)
Initializes the RNT runtime with the selected storage backend.
Definition RNT_C_API.cpp:674
int(* rnt_generator_fn)(void *ctx, const char *args, size_t offset, size_t limit, rnt_tuple_sink_t sink)
Tuple-producing callback backing an ephemeral relation.
Definition RNT_C_API.h:169
NT_API int rnt_register_relation(const char *path)
Registers a RELATION object at the given path.
Definition RNT_C_API.cpp:985
NT_API int rnt_clear_relation(const char *relation_path)
Resets a relation's Merkle root to the empty-tree state.
Definition RNT_C_API.cpp:1136
NT_API int rnt_drop_ephemeral_relation(const char *session_hash, const char *name)
Drops a named ephemeral relation, releasing its session-ownership pin.
Definition RNT_C_API.cpp:914
void * rnt_tuple_sink_t
Opaque sink passed to a generator callback.
Definition RNT_C_API.h:150
NT_API int rnt_vm_cursor_close(rnt_cursor_t vm_cursor)
Closes a VM cursor, releases all plan nodes, cursors, and handles.
Definition RNT_C_API.cpp:1271
NT_API int rnt_relation_root(const char *relation_path, char **root_hash_out)
Returns the current Merkle root hash for a relation.
Definition RNT_C_API.cpp:1153
void * rnt_plan_t
Opaque plan node tree, built via rnt_plan_assemble calls.
Definition RNT_C_API.h:478
NT_API int rnt_branch_advance(const char *branch_path, const char *new_hash)
Atomically advances a branch to point at a new branch-tree root.
Definition RNT_C_API.cpp:957
NT_API rnt_cursor_t rnt_cursor_open(rnt_handle_t handle)
Opens a cursor on the relation referenced by handle.
Definition RNT_C_API.cpp:1180
NT_API int rnt_branch_target(rnt_handle_t handle, char **target_hash_out)
Reads the current branch-tree root hash from a BRANCH object.
Definition RNT_C_API.cpp:939
NT_API int rnt_sink_emit(rnt_tuple_sink_t sink, const char *tuple_kv)
Emits one tuple from inside a generator callback.
Definition RNT_C_API.cpp:837
NT_API int rnt_register_branch(const char *path, const char *target_hash)
Registers a BRANCH object at the given path pointing at a branch-tree root.
Definition RNT_C_API.cpp:1011
NT_API int rnt_register_ephemeral_relation(const char *session_hash, int named, const char *name, rnt_generator_fn generator, void *generator_ctx, int cardinality, const char *generator_identity, const char *schema_kv, const char *dependencies, char **path_out)
Registers an ephemeral relation owned by a session.
Definition RNT_C_API.cpp:845
NT_API int rnt_session_open(void *connection_context, char **session_hash_out)
Opens a session and registers it at /system/sessions/<hash>.
Definition RNT_C_API.cpp:715
void * rnt_cursor_t
Opaque cursor over a relation, driven by the VM or used directly.
Definition RNT_C_API.h:49
NT_API int rnt_session_close(const char *session_hash)
Closes a session, unregistering it from /system/sessions/<hash>.
Definition RNT_C_API.cpp:737
NT_API int rnt_list_snapshot_relations(const char *snapshot_hash, char **out)
Lists all relations stored in a specific snapshot.
Definition RNT_C_API.cpp:1067
NT_API void rnt_free_string(char *s)
Releases a string allocated by the API.
Definition RNT_C_API.cpp:1215
NT_API void rnt_plan_free(rnt_plan_t plan)
Releases a plan that was built but not yet executed.
Definition RNT_C_API.cpp:1247
NT_API int rnt_list_branch_multigroups(const char *branch_path, char **out)
Lists all multigroups bound to a branch.
Definition RNT_C_API.cpp:1053
NT_API int rnt_cursor_next(rnt_cursor_t cursor, char **tuple_out)
Advances the cursor and returns the next tuple as a kv string.
Definition RNT_C_API.cpp:1195
NT_API int rnt_vm_cursor_next(rnt_cursor_t vm_cursor, char **tuple_out)
Advances a VM cursor and returns the next merged tuple as a kv string.
Definition RNT_C_API.cpp:1258
NT_API int rnt_firewall(const char *auth_method, char **claims_out)
Runs PermissionsManager::Firewall for a connection.
Definition RNT_C_API.cpp:709
NT_API int rnt_unlink_tuple(const char *relation_path, const char *tuple_hash)
Removes a tuple from the relation's Merkle tree and tuple store.
Definition RNT_C_API.cpp:1115
NT_API rnt_plan_t rnt_plan_assemble(PlanAction action)
Builds one plan node from action and returns the resulting subtree.
Definition RNT_C_API.cpp:1226
NT_API int rnt_close_handle(rnt_handle_t handle)
Closes a handle, running HandlerManager::Close and Unmonitor.
Definition RNT_C_API.cpp:932
NT_API int rnt_cursor_close(rnt_cursor_t cursor)
Closes a cursor and releases its resources.
Definition RNT_C_API.cpp:1208
NT_API int rnt_list_relations(const char *branch_mg_path, char **out)
Lists all relations of a specific multigroup under a branch.
Definition RNT_C_API.cpp:1033
void * rnt_handle_t
Opaque handle to a registry object opened through HandlerManager.
Definition RNT_C_API.h:46
NT_API int rnt_link_tuple(const char *relation_path, const char *kv_attrs, char **hash_out)
Stores a tuple and links it to the relation at the given path.
Definition RNT_C_API.cpp:1086
NT_API int rnt_session_set_branch(const char *session_hash, const char *branch_name, const char *target_hash)
Sets a per-session override for a branch.
Definition RNT_C_API.cpp:762
Declares the logic execution boundary for relational and higher-order workloads.
A single plan-construction request.
Definition RNT_C_API.h:562
JOIN context: nested-loop join of two child plans.
Definition RNT_C_API.h:496
MATERIALIZE context: caches source on its first scan, then replays the cache on later scans without t...
Definition RNT_C_API.h:534
PROJECT context: keeps only the named attributes of source.
Definition RNT_C_API.h:519
RENAME context: returns source, with the keys of pairs the values of it.
Definition RNT_C_API.h:545
SCAN context: reads all tuples from a stored relation.
Definition RNT_C_API.h:486
TAKE context: passes at most limit tuples from source, then stops.
Definition RNT_C_API.h:507
UNION context.
Definition RNT_C_API.h:552