Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Initial support of table function #112

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ arrow = { version = "29", default-features = false, features = ["prettyprint", "
rust_decimal = "1.14"
strum = { version = "0.24", features = ["derive"] }
r2d2 = { version = "0.8.9", optional = true }
num-derive = { version = "0.3.3" }
num-traits = { version = "0.2.15" }

[dev-dependencies]
doc-comment = "0.3"
Expand Down
9 changes: 9 additions & 0 deletions src/inner_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use super::{Appender, Config, Connection, Result};
use crate::error::{result_from_duckdb_appender, result_from_duckdb_arrow, result_from_duckdb_prepare, Error};
use crate::raw_statement::RawStatement;
use crate::statement::Statement;
use crate::table_function::TableFunction;

pub struct InnerConnection {
pub db: ffi::duckdb_database,
Expand Down Expand Up @@ -88,6 +89,14 @@ impl InnerConnection {
Ok(Statement::new(conn, unsafe { RawStatement::new(c_stmt) }))
}

pub fn register_table_funcion(&mut self, table_function: TableFunction) -> Result<()> {
unsafe {
// FIXME
let _ = ffi::duckdb_register_table_function(self.con, table_function.ptr);
}
Ok(())
}

pub fn appender<'a>(&mut self, conn: &'a Connection, table: &str, schema: &str) -> Result<Appender<'a>> {
let mut c_app: ffi::duckdb_appender = ptr::null_mut();
let c_table = CString::new(table).unwrap();
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ mod row;
mod statement;
mod transaction;

/// The duckdb table function interface
pub mod table_function;
pub mod types;

use table_function::TableFunction;

pub(crate) mod util;

// Number of cached prepared statements we'll hold on to.
Expand Down Expand Up @@ -512,6 +516,12 @@ impl Connection {
self.db.borrow().is_autocommit()
}

/// Register the given TableFunction with the current db
#[inline]
pub fn register_table_function(&self, table_function: TableFunction) -> Result<()> {
self.db.borrow_mut().register_table_funcion(table_function)
}

/// Creates a new connection to the already-opened database.
pub fn try_clone(&self) -> Result<Self> {
let inner = self.db.borrow().try_clone()?;
Expand Down
2 changes: 1 addition & 1 deletion src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl<'stmt> Row<'stmt> {
Error::InvalidColumnType(idx, self.stmt.column_name_unwrap(idx).into(), value.data_type())
}
FromSqlError::OutOfRange(i) => Error::IntegralValueOutOfRange(idx, i),
FromSqlError::Other(err) => Error::FromSqlConversionFailure(idx as usize, value.data_type(), err),
FromSqlError::Other(err) => Error::FromSqlConversionFailure(idx, value.data_type(), err),
#[cfg(feature = "uuid")]
FromSqlError::InvalidUuidSize(_) => {
Error::InvalidColumnType(idx, self.stmt.column_name_unwrap(idx).into(), value.data_type())
Expand Down
Loading