duckdb-extension-framework 0.3.0

Purely experimental DuckDB extension framework
Documentation
use crate::constants::DuckDBType;
use crate::duckly::{
    duckdb_create_logical_type, duckdb_destroy_logical_type, duckdb_get_type_id,
    duckdb_logical_type,
};
use num_traits::FromPrimitive;

#[derive(Debug)]
pub struct LogicalType {
    pub(crate) typ: duckdb_logical_type,
}

impl LogicalType {
    pub fn new(typ: DuckDBType) -> Self {
        unsafe {
            Self {
                typ: duckdb_create_logical_type(typ as u32),
            }
        }
    }
    pub fn type_id(&self) -> DuckDBType {
        let id = unsafe { duckdb_get_type_id(self.typ) };

        FromPrimitive::from_u32(id).unwrap()
    }
}

impl From<duckdb_logical_type> for LogicalType {
    fn from(ptr: duckdb_logical_type) -> Self {
        Self { typ: ptr }
    }
}

impl Drop for LogicalType {
    fn drop(&mut self) {
        unsafe {
            duckdb_destroy_logical_type(&mut self.typ);
        }
    }
}