Skip to main content

Module ffi

Module ffi 

Source
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§

LaminarConnection
Opaque connection handle for FFI.
LaminarQueryResult
Opaque query result handle for FFI.
LaminarQueryStream
Opaque query stream handle for FFI.
LaminarRecordBatch
Opaque record batch handle for FFI.
LaminarSchema
Opaque schema handle for FFI.
LaminarSubscriptionHandle
Opaque handle for a callback-based subscription.
LaminarWriter
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 RecordBatch from Arrow C Data Interface for writing.
laminar_batch_export
Export a RecordBatch to the Arrow C Data Interface.
laminar_batch_export_column
Export a single column from a RecordBatch to the Arrow C Data Interface.
laminar_batch_free
Free a record batch handle.
laminar_batch_import
Import a RecordBatch from 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 LaminarDB library 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§

LaminarErrorCallback
Callback function type for errors.
LaminarSubscriptionCallback
Callback function type for subscription data.