quackdb_internal/handles/
arrow.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::{ops::Deref, sync::Arc};

use crate::ffi;

use super::{ConnectionHandle, PreparedStatementHandle};

#[derive(Debug)]
pub struct ArrowResultHandle {
    raw: ffi::duckdb_arrow,
    _parent: ArrowResultParent,
}

#[derive(Debug)]
pub enum ArrowResultParent {
    Connection(Arc<ConnectionHandle>),
    Statement(Arc<PreparedStatementHandle>),
}

impl ArrowResultHandle {
    /// # Safety
    /// * Takes ownership of `raw`
    pub unsafe fn from_raw_connection(
        raw: ffi::duckdb_arrow,
        connection: Arc<ConnectionHandle>,
    ) -> Self {
        Self {
            raw,
            _parent: ArrowResultParent::Connection(connection),
        }
    }
    /// # Safety
    /// * Takes ownership of `raw`
    pub unsafe fn from_raw_statement(
        raw: ffi::duckdb_arrow,
        statement: Arc<PreparedStatementHandle>,
    ) -> Self {
        Self {
            raw,
            _parent: ArrowResultParent::Statement(statement),
        }
    }
}

impl Deref for ArrowResultHandle {
    type Target = ffi::duckdb_arrow;

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

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