pub struct Connection { /* private fields */ }Expand description
Thread-safe database connection for FFI.
This is a wrapper around LaminarDB that provides:
- Explicit
Send + Syncmarkers for FFI safety close()method returningResultfor error handling- Untyped Arrow API without Rust trait bounds
§Example
use laminar_db::api::Connection;
let conn = Connection::open()?;
conn.execute("CREATE SOURCE trades (symbol VARCHAR, price DOUBLE)")?;
let result = conn.query("SELECT * FROM trades")?;
println!("Got {} rows", result.num_rows());
conn.close()?;Implementations§
Source§impl Connection
impl Connection
Sourcepub fn open() -> Result<Self, ApiError>
pub fn open() -> Result<Self, ApiError>
Open an in-memory database with default settings.
§Errors
Returns ApiError if database creation fails.
Sourcepub fn open_with_config(config: LaminarConfig) -> Result<Self, ApiError>
pub fn open_with_config(config: LaminarConfig) -> Result<Self, ApiError>
Sourcepub fn execute(&self, sql: &str) -> Result<ExecuteResult, ApiError>
pub fn execute(&self, sql: &str) -> Result<ExecuteResult, ApiError>
Execute a SQL statement (blocking wrapper around async).
Supports: CREATE SOURCE/SINK/STREAM, DROP, SELECT, INSERT INTO,
SHOW, DESCRIBE, EXPLAIN, CREATE MATERIALIZED VIEW.
§Errors
Returns ApiError if SQL parsing, planning, or execution fails.
§Panics
Panics if the internal thread used for async execution panics.
Sourcepub fn query(&self, sql: &str) -> Result<QueryResult, ApiError>
pub fn query(&self, sql: &str) -> Result<QueryResult, ApiError>
Execute SQL and wait for all results (materialized).
§Errors
Returns ApiError if execution fails or the result is not a query.
Sourcepub fn query_stream(&self, sql: &str) -> Result<QueryStream, ApiError>
pub fn query_stream(&self, sql: &str) -> Result<QueryStream, ApiError>
Execute SQL with streaming results.
§Errors
Returns ApiError if execution fails or the result is not a query.
Sourcepub fn insert(
&self,
source_name: &str,
batch: RecordBatch,
) -> Result<u64, ApiError>
pub fn insert( &self, source_name: &str, batch: RecordBatch, ) -> Result<u64, ApiError>
Insert a RecordBatch directly into a source.
Returns the number of rows inserted.
§Errors
Returns ApiError if the source is not found or ingestion fails.
Sourcepub fn get_schema(&self, name: &str) -> Result<SchemaRef, ApiError>
pub fn get_schema(&self, name: &str) -> Result<SchemaRef, ApiError>
Get schema for a source or stream.
§Errors
Returns ApiError::table_not_found if the name is not found.
Sourcepub fn list_sources(&self) -> Vec<String>
pub fn list_sources(&self) -> Vec<String>
List all source names.
Sourcepub fn list_streams(&self) -> Vec<String>
pub fn list_streams(&self) -> Vec<String>
List all stream names.
Sourcepub fn list_sinks(&self) -> Vec<String>
pub fn list_sinks(&self) -> Vec<String>
List all sink names.
Sourcepub fn close(self) -> Result<(), ApiError>
pub fn close(self) -> Result<(), ApiError>
Explicitly close the connection.
Unlike Drop, this returns errors and ensures cleanup completes.
§Errors
Currently always succeeds.
Sourcepub fn checkpoint(&self) -> Result<u64, ApiError>
pub fn checkpoint(&self) -> Result<u64, ApiError>
Sourcepub fn is_checkpoint_enabled(&self) -> bool
pub fn is_checkpoint_enabled(&self) -> bool
Check if checkpointing is enabled.
Sourcepub fn source_info(&self) -> Vec<SourceInfo>
pub fn source_info(&self) -> Vec<SourceInfo>
List source info with schemas and watermark columns.
Sourcepub fn stream_info(&self) -> Vec<StreamInfo>
pub fn stream_info(&self) -> Vec<StreamInfo>
List stream info with SQL.
Sourcepub fn query_info(&self) -> Vec<QueryInfo>
pub fn query_info(&self) -> Vec<QueryInfo>
List active/completed query info.
Sourcepub fn pipeline_topology(&self) -> PipelineTopology
pub fn pipeline_topology(&self) -> PipelineTopology
Get the pipeline topology graph.
Sourcepub fn pipeline_state(&self) -> String
pub fn pipeline_state(&self) -> String
Get the pipeline state as a string (“Created”, “Running”, “Stopped”, etc.).
Sourcepub fn pipeline_watermark(&self) -> i64
pub fn pipeline_watermark(&self) -> i64
Get the global pipeline watermark.
Sourcepub fn total_events_processed(&self) -> u64
pub fn total_events_processed(&self) -> u64
Get total events processed across all sources.
Sourcepub fn source_count(&self) -> usize
pub fn source_count(&self) -> usize
Get the number of registered sources.
Sourcepub fn sink_count(&self) -> usize
pub fn sink_count(&self) -> usize
Get the number of registered sinks.
Sourcepub fn active_query_count(&self) -> usize
pub fn active_query_count(&self) -> usize
Get the number of active queries.
Sourcepub fn metrics(&self) -> PipelineMetrics
pub fn metrics(&self) -> PipelineMetrics
Get pipeline-wide metrics snapshot.
Sourcepub fn source_metrics(&self, name: &str) -> Option<SourceMetrics>
pub fn source_metrics(&self, name: &str) -> Option<SourceMetrics>
Get metrics for a specific source.
Sourcepub fn all_source_metrics(&self) -> Vec<SourceMetrics>
pub fn all_source_metrics(&self) -> Vec<SourceMetrics>
Get metrics for all sources.
Sourcepub fn stream_metrics(&self, name: &str) -> Option<StreamMetrics>
pub fn stream_metrics(&self, name: &str) -> Option<StreamMetrics>
Get metrics for a specific stream.
Sourcepub fn all_stream_metrics(&self) -> Vec<StreamMetrics>
pub fn all_stream_metrics(&self) -> Vec<StreamMetrics>
Get metrics for all streams.
Sourcepub fn subscribe(
&self,
stream_name: &str,
) -> Result<ArrowSubscription, ApiError>
pub fn subscribe( &self, stream_name: &str, ) -> Result<ArrowSubscription, ApiError>
Subscribe to a named stream, returning an ArrowSubscription.
The stream must already exist (created via CREATE STREAM ... AS SELECT ...).
Returns a channel-based subscription that delivers RecordBatches as
they are produced by the streaming pipeline.
§Errors
Returns ApiError if the stream is not found.
Trait Implementations§
impl Send for Connection
impl Sync for Connection
Auto Trait Implementations§
impl Freeze for Connection
impl !RefUnwindSafe for Connection
impl Unpin for Connection
impl UnsafeUnpin for Connection
impl !UnwindSafe for Connection
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
§impl<T> AsAny for T
impl<T> AsAny for T
§fn any_ref(&self) -> &(dyn Any + Send + Sync + 'static)
fn any_ref(&self) -> &(dyn Any + Send + Sync + 'static)
dyn Any reference to the object: Read more§fn as_any(self: Arc<T>) -> Arc<dyn Any + Send + Sync>
fn as_any(self: Arc<T>) -> Arc<dyn Any + Send + Sync>
Arc<dyn Any> reference to the object: Read more§fn into_any(self: Box<T>) -> Box<dyn Any + Send + Sync>
fn into_any(self: Box<T>) -> Box<dyn Any + Send + Sync>
Box<dyn Any>: Read more§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
std::any::type_name, since Any does not provide it and
Any::type_id is useless as a debugging aid (its Debug is just a mess of hex digits).Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Scope for T
impl<T> Scope for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.