Skip to main content

Connection

Struct Connection 

Source
pub struct Connection { /* private fields */ }
Expand description

Wraps the duckdb_connection and duckdb_database provided to your extension at load time.

Connection implements Registrar, offering a single, uniform API for registering all extension components. It also exposes register_replacement_scan and register_replacement_scan_with_data, which require the duckdb_database handle and therefore cannot be part of the Registrar trait.

§Obtaining a Connection

Use init_extension_v2 (or the entry_point_v2! macro). Both pass a &Connection to your registration callback.

§Version compatibility

Connection provides a uniform API across DuckDB 1.4.x and 1.5.x. When future DuckDB releases add new C API surface, additional methods will be gated on the corresponding feature flag.

Implementations§

Source§

impl Connection

Source

pub const fn as_raw_connection(&self) -> duckdb_connection

Return the raw duckdb_connection handle.

Use this to call C API functions that quack-rs does not yet wrap.

Source

pub const fn as_raw_database(&self) -> duckdb_database

Return the raw duckdb_database handle.

Use this to call C API functions that require the database handle, such as replacement scan registration or (with duckdb-1-5) config option registration.

Source

pub unsafe fn register_replacement_scan( &self, callback: ReplacementScanFn, extra_data: *mut c_void, delete_callback: duckdb_delete_callback_t, )

Register a replacement scan backed by a raw function pointer and extra data.

For the ergonomic owned-data variant, see register_replacement_scan_with_data.

§Safety
  • The underlying duckdb_database must be valid.
  • extra_data must remain valid until delete_callback is called (or until the database is closed if delete_callback is None).
Source

pub unsafe fn register_replacement_scan_with_data<T: 'static>( &self, callback: ReplacementScanFn, data: T, )

Register a replacement scan with owned extra data.

Boxes data and registers a drop destructor automatically. This is the safe, ergonomic alternative to register_replacement_scan.

§Safety

The underlying duckdb_database must be valid.

Trait Implementations§

Source§

impl Registrar for Connection

Source§

unsafe fn register_scalar( &self, builder: ScalarFunctionBuilder, ) -> Result<(), ExtensionError>

Register a scalar function. Read more
Source§

unsafe fn register_scalar_set( &self, builder: ScalarFunctionSetBuilder, ) -> Result<(), ExtensionError>

Register a scalar function set (multiple overloads under one name). Read more
Source§

unsafe fn register_aggregate( &self, builder: AggregateFunctionBuilder, ) -> Result<(), ExtensionError>

Register an aggregate function. Read more
Source§

unsafe fn register_aggregate_set( &self, builder: AggregateFunctionSetBuilder, ) -> Result<(), ExtensionError>

Register an aggregate function set (multiple overloads under one name). Read more
Source§

unsafe fn register_table( &self, builder: TableFunctionBuilder, ) -> Result<(), ExtensionError>

Register a table function. Read more
Source§

unsafe fn register_sql_macro( &self, sql_macro: SqlMacro, ) -> Result<(), ExtensionError>

Register a SQL macro (scalar or table-returning). Read more
Source§

unsafe fn register_cast( &self, builder: CastFunctionBuilder, ) -> Result<(), ExtensionError>

Register a custom type cast function. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.