Skip to main content

better_duck_core/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! `better-duck-core` — a safe, low-level Rust wrapper around the
3//! [DuckDB](https://duckdb.org) C API (vendored in-workspace via `better-duck-sys`).
4//!
5//! This crate provides:
6//! - A high-level [`connection::Connection`] for opening databases and executing SQL.
7//! - Low-level raw types (`RawConnection`, `DuckResult`, `DuckRow`) for advanced use.
8//! - Type conversion traits ([`types::DuckDialect`], [`types::appendable::AppendAble`]) for
9//!   mapping between Rust types and DuckDB values.
10
11pub extern crate better_duck_sys as libduckdb_sys;
12/// Re-export of the raw `better-duck-sys` FFI bindings.
13pub use better_duck_sys as ffi;
14
15/// Async facade over [`connection::Connection`], gated by the `async` feature.
16#[cfg(feature = "async")]
17pub mod asynchronous;
18/// DuckDB database configuration.
19pub mod config;
20/// High-level DuckDB connection type.
21pub mod connection;
22/// A shared, cloneable handle to an open DuckDB database.
23pub mod database;
24/// Error types returned by this crate.
25pub mod error;
26mod helpers;
27/// An `r2d2` connection pool backed by a shared [`Database`](database::Database).
28#[cfg(feature = "pool")]
29pub mod pool;
30mod raw;
31/// An owned, thread-safe, fully materialized query result.
32pub mod result_set;
33/// DuckDB type system and value conversion traits.
34pub mod types;
35/// User-defined DuckDB functions: scalar functions and table functions.
36#[cfg(feature = "udf")]
37pub mod udf;
38
39/// Async facade over [`connection::Connection`].
40#[cfg(feature = "async")]
41pub use asynchronous::AsyncConnection;
42/// Async facade over [`Database`].
43#[cfg(feature = "async")]
44pub use asynchronous::AsyncDatabase;
45/// Async facade over [`pool::Pool`].
46#[cfg(all(feature = "async", feature = "pool"))]
47pub use asynchronous::AsyncPool;
48
49/// Registers a plain Rust function as a DuckDB scalar function. See [`udf`].
50#[cfg(feature = "udf")]
51pub use better_duck_macros::duckdb_scalar;
52/// Registers a plain Rust function as a DuckDB table function. See [`udf`].
53#[cfg(feature = "udf")]
54pub use better_duck_macros::duckdb_table_function;
55/// DuckDB database configuration.
56pub use config::{library_version, AccessMode, Config, ConfigFlag, DefaultNullOrder, DefaultOrder};
57/// A shared, cloneable handle to an open DuckDB database.
58pub use database::Database;
59/// A DuckDB appender for bulk-inserting rows into a table.
60pub use raw::appender::Appender;
61/// A thread-safe handle for interrupting or observing one running query.
62pub use raw::connection::{QueryControl, QueryProgress};
63/// A parsed batch of SQL statements, each preparable on demand.
64pub use raw::extracted::ExtractedStatements;
65/// Incremental execution of a prepared statement, one task at a time.
66pub use raw::pending::{OwnedPending, PendingResult, PendingState};
67/// A fully iterable DuckDB query result.
68pub use raw::result::{DuckResult, ResultType};
69/// A single row from a DuckDB query result.
70pub use raw::row::DuckRow;
71/// A prepared statement suitable for caching and re-execution.
72pub use raw::statement::{CachedStatement, StatementType};
73
74pub use raw::table_description::TableDescription;
75
76pub use raw::data_chunk::DataChunk;
77
78pub use raw::profiling::ProfilingNode;
79
80pub use raw::client_context::ClientContext;
81
82pub use raw::owned_value::{IntervalParts, OwnedValue};
83
84pub use raw::owned_vector::OwnedVector;
85
86pub use raw::selection_vector::SelectionVector;
87
88/// Numeric/temporal conversion helpers backed by DuckDB's own routines.
89pub use types::convert::{
90    double_to_hugeint, double_to_uhugeint, hugeint_to_double, parts_to_timestamp_micros,
91    timestamp_micros_to_parts, uhugeint_to_double, TimestampParts,
92};
93
94pub use raw::instance_cache::InstanceCache;
95
96pub use raw::task_state::{execute_tasks, TaskState};
97
98#[cfg(feature = "udf")]
99pub use raw::expression::Expression;
100/// An owned, thread-safe, fully materialized query result.
101pub use result_set::ResultSet;
102/// Trait for binding values to DuckDB prepared statements and appenders.
103pub use types::appendable::AppendAble;
104/// A calendar date value for use without the `chrono` feature.
105#[cfg(not(feature = "chrono"))]
106pub use types::date_native::DuckDate;
107/// A time-of-day value for use without the `chrono` feature.
108#[cfg(not(feature = "chrono"))]
109pub use types::date_native::DuckTime;