Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
feat: add missing functions to LogicalType
Browse files Browse the repository at this point in the history
  • Loading branch information
Mause committed Nov 9, 2022
1 parent c8e7afe commit 9136cdd
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/logical_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::constants::DuckDBType;
use crate::duckly::{
duckdb_create_logical_type, duckdb_create_map_type, duckdb_destroy_logical_type,
duckdb_get_type_id, duckdb_logical_type,
duckdb_create_list_type, duckdb_create_logical_type, duckdb_create_map_type,
duckdb_destroy_logical_type, duckdb_get_type_id, duckdb_logical_type,
};
use num_traits::FromPrimitive;

Expand All @@ -18,13 +18,38 @@ impl LogicalType {
}
}
}
/// Creates a map type from its key type and value type.
///
/// # Arguments
/// * `type`: The key type and value type of map type to create.
/// * `returns`: The logical type.
pub fn new_map_type(key: &LogicalType, value: &LogicalType) -> Self {
unsafe {
Self {
typ: duckdb_create_map_type(key.typ, value.typ),
}
}
}
/// Creates a list type from its child type.
///
/// # Arguments
/// * `type`: The child type of list type to create.
/// * `returns`: The logical type.
pub fn new_list_type(child_type: &LogicalType) -> Self {
unsafe {
Self {
typ: duckdb_create_list_type(child_type.typ),
}
}
}
pub fn new_struct_type(_names: &[&str], _types: &[&LogicalType]) -> Self {
todo!()
}

/// Retrieves the type class of a `duckdb_logical_type`.
///
/// # Arguments
/// * `returns`: The type id
pub fn type_id(&self) -> DuckDBType {
let id = unsafe { duckdb_get_type_id(self.typ) };

Expand Down

0 comments on commit 9136cdd

Please sign in to comment.