Skip to main content

init_extension_v2

Function init_extension_v2 

Source
pub unsafe fn init_extension_v2<F>(
    info: duckdb_extension_info,
    access: *const duckdb_extension_access,
    api_version: &str,
    register: F,
) -> bool
Expand description

Core entry point helper — sets up a Connection and calls your registration closure.

Identical to init_extension except that the callback receives a &Connection instead of a raw duckdb_connection. Connection implements Registrar and also exposes the duckdb_database handle for replacement scan registration.

Prefer this over init_extension for new extensions. The raw duckdb_connection entry point is retained for backward compatibility.

The closure runs in one transaction, so a failed LOAD leaves no catalog entry behind; casts, replacement scans and configuration options are not rolled back. See the module documentation.

§Return value

Returns true if initialization succeeded, false on any error.

§Safety

  • info must be the duckdb_extension_info passed by DuckDB to your entry point.
  • access must be the *const duckdb_extension_access passed by DuckDB.
  • Both pointers must remain valid for the duration of this call.

§Example

use quack_rs::entry_point::init_extension_v2;
use quack_rs::connection::Registrar;

#[unsafe(no_mangle)]
pub unsafe extern "C" fn my_ext_init_c_api(
    info: libduckdb_sys::duckdb_extension_info,
    access: *const libduckdb_sys::duckdb_extension_access,
) -> bool {
    unsafe {
        init_extension_v2(info, access, quack_rs::DUCKDB_API_VERSION, |con| {
            // unsafe { con.register_scalar(builder)?; }
            Ok(())
        })
    }
}