Expand description
C FFI layer for LaminarDB.
Enable with the ffi feature flag:
laminar-db = { version = "0.1", features = ["ffi"] }This module provides extern "C" functions for calling LaminarDB from C
and any language with C FFI support (Python, Java, Node.js, .NET, etc.).
C FFI layer for LaminarDB.
This module provides extern "C" functions for calling LaminarDB from C
and any language with C FFI support (Python, Java, Node.js, .NET, etc.).
§Design
- Opaque handles: C sees pointers, not struct layouts
- Explicit memory management: Caller frees with
*_free()functions - Error codes: All functions return
i32(0 = success, negative = error) - Out-parameters: Results returned via pointer arguments
- Thread-local errors:
laminar_last_error()returns the last error message
§Example (C)
#include "laminar.h"
int main() {
LaminarConnection* conn = NULL;
int32_t rc = laminar_open(&conn);
if (rc != LAMINAR_OK) {
printf("Error: %s\n", laminar_last_error());
return 1;
}
rc = laminar_execute(conn, "CREATE SOURCE test (id BIGINT)", NULL);
laminar_close(conn);
return 0;
}Structs§
- Laminar
Connection - Opaque connection handle for FFI.
- Laminar
Query Result - Opaque query result handle for FFI.
- Laminar
Query Stream - Opaque query stream handle for FFI.
- Laminar
Record Batch - Opaque record batch handle for FFI.
- Laminar
Schema - Opaque schema handle for FFI.
- Laminar
Subscription Handle - Opaque handle for a callback-based subscription.
- Laminar
Writer - Opaque writer handle for FFI.
Constants§
- LAMINAR_
ERR_ CONNECTION - Connection error.
- LAMINAR_
ERR_ INGESTION - Data ingestion error.
- LAMINAR_
ERR_ INTERNAL - Internal error.
- LAMINAR_
ERR_ INVALID_ UTF8 - Invalid UTF-8 string.
- LAMINAR_
ERR_ NULL_ POINTER - Null pointer was passed to a function.
- LAMINAR_
ERR_ QUERY - Query execution error.
- LAMINAR_
ERR_ SCHEMA_ MISMATCH - Schema mismatch error.
- LAMINAR_
ERR_ SHUTDOWN - Database is shutting down.
- LAMINAR_
ERR_ SUBSCRIPTION - Subscription error.
- LAMINAR_
ERR_ TABLE_ EXISTS - Table/source already exists.
- LAMINAR_
ERR_ TABLE_ NOT_ FOUND - Table/source not found.
- LAMINAR_
EVENT_ DELETE - Event type: delete (-1 weight).
- LAMINAR_
EVENT_ INSERT - Event type: insert (+1 weight).
- LAMINAR_
EVENT_ SNAPSHOT - Event type: snapshot (initial state load).
- LAMINAR_
EVENT_ UPDATE - Event type: update (decomposed to delete + insert).
- LAMINAR_
EVENT_ WATERMARK - Event type: watermark progress (no data).
- LAMINAR_
OK - Success return code.
Functions§
- laminar_
batch_ ⚠create - Create a
RecordBatchfrom Arrow C Data Interface for writing. - laminar_
batch_ ⚠export - Export a
RecordBatchto the Arrow C Data Interface. - laminar_
batch_ ⚠export_ column - Export a single column from a
RecordBatchto the Arrow C Data Interface. - laminar_
batch_ ⚠free - Free a record batch handle.
- laminar_
batch_ ⚠import - Import a
RecordBatchfrom the Arrow C Data Interface. - laminar_
batch_ ⚠num_ columns - Get the number of columns in a record batch.
- laminar_
batch_ ⚠num_ rows - Get the number of rows in a record batch.
- laminar_
clear_ error - Clear the last error.
- laminar_
close ⚠ - Close a database connection.
- laminar_
execute ⚠ - Execute a SQL statement.
- laminar_
get_ ⚠schema - Get schema for a source.
- laminar_
is_ ⚠closed - Check if the connection is closed.
- laminar_
last_ error - Get the last error message.
- laminar_
last_ error_ code - Get the last error code.
- laminar_
list_ ⚠sources - List all sources as JSON array.
- laminar_
open ⚠ - Open a new database connection.
- laminar_
query ⚠ - Execute a query and get materialized results.
- laminar_
query_ ⚠stream - Execute a query with streaming results.
- laminar_
result_ ⚠free - Free a query result handle.
- laminar_
result_ ⚠get_ batch - Get a batch by index from a query result.
- laminar_
result_ ⚠num_ batches - Get the number of batches in a query result.
- laminar_
result_ ⚠num_ rows - Get the total row count from a query result.
- laminar_
result_ ⚠schema - Get the schema from a query result.
- laminar_
schema_ ⚠export - Export just the schema to the Arrow C Data Interface.
- laminar_
schema_ ⚠field_ name - Get the name of a field by index.
- laminar_
schema_ ⚠field_ type - Get the type of a field by index.
- laminar_
schema_ ⚠free - Free a schema handle.
- laminar_
schema_ ⚠num_ fields - Get the number of fields in a schema.
- laminar_
start ⚠ - Start the streaming pipeline.
- laminar_
stream_ ⚠cancel - Cancel a query stream.
- laminar_
stream_ ⚠free - Free a query stream handle.
- laminar_
stream_ ⚠is_ active - Check if a query stream is still active.
- laminar_
stream_ ⚠next - Get the next batch from a query stream (blocking).
- laminar_
stream_ ⚠schema - Get the schema from a query stream.
- laminar_
stream_ ⚠try_ next - Try to get the next batch from a query stream (non-blocking).
- laminar_
string_ ⚠free - Free a string allocated by
LaminarDB. - laminar_
subscribe_ ⚠callback - Create a callback-based subscription.
- laminar_
subscription_ ⚠cancel - Cancel a callback-based subscription.
- laminar_
subscription_ ⚠free - Free a subscription handle.
- laminar_
subscription_ ⚠is_ active - Check if a subscription is still active.
- laminar_
subscription_ ⚠user_ data - Get the user data pointer from a subscription handle.
- laminar_
version - Get the
LaminarDBlibrary version. - laminar_
writer_ ⚠close - Close the writer and release resources.
- laminar_
writer_ ⚠create - Create a writer for a source.
- laminar_
writer_ ⚠flush - Flush buffered data.
- laminar_
writer_ ⚠free - Free a writer handle.
- laminar_
writer_ ⚠write - Write a record batch to the source.
Type Aliases§
- Laminar
Error Callback - Callback function type for errors.
- Laminar
Subscription Callback - Callback function type for subscription data.