quackdb_internal/handles/
database.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::{ops::Deref, sync::Arc};

use crate::ffi;

#[derive(Debug)]
pub struct DatabaseHandle {
    raw: ffi::duckdb_database,
}

impl DatabaseHandle {
    /// # Safety
    /// * Takes ownership of `raw`
    pub unsafe fn from_raw(raw: ffi::duckdb_database) -> Arc<Self> {
        Arc::new(Self { raw })
    }
}

impl Drop for DatabaseHandle {
    fn drop(&mut self) {
        unsafe { ffi::duckdb_close(&mut self.raw) }
    }
}

impl Deref for DatabaseHandle {
    type Target = ffi::duckdb_database;

    fn deref(&self) -> &Self::Target {
        &self.raw
    }
}