summaryrefslogtreecommitdiff
path: root/src/duckdb/Types.zig
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-05 22:20:19 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-05 22:20:46 +0200
commit8efa7cb0013aae1708e2d815b7fa65f055062159 (patch)
tree4b815a71d8d09b00a29d9435f5b52369fa482081 /src/duckdb/Types.zig
parent2c5149d5ca84b28d371dffa2c5ea3cae53c93a8e (diff)
Results with proper conversion
Diffstat (limited to 'src/duckdb/Types.zig')
-rw-r--r--src/duckdb/Types.zig66
1 files changed, 0 insertions, 66 deletions
diff --git a/src/duckdb/Types.zig b/src/duckdb/Types.zig
deleted file mode 100644
index 2a12cd2..0000000
--- a/src/duckdb/Types.zig
+++ /dev/null
@@ -1,66 +0,0 @@
-const std = @import("std");
-const c = @cImport({
- @cInclude("duckdb.h");
-});
-
-pub fn unpack_type(T: type) type {
- return switch(@typeInfo(T)) {
- .Bool, .Int, .Float => T,
- .Pointer => |p| switch (p.size) {
- .Slice => if (p.child == u8) c.duckdb_string_t else
- @compileError("Invalid type for output data"),
- else => @compileError("Invalid type for output data")
- },
- // .Array =>
- // .Struct =>
- // .Enum =>
- // .Union =>
- else => @compileError("Invalid type for output data")
- };
-}
-
-pub fn valid_unpack(column_type: c.DUCKDB_TYPE, T: type) bool {
- switch (column_type) {
- c.DUCKDB_TYPE_BOOLEAN => if(T == bool) return true else return false,
- c.DUCKDB_TYPE_TINYINT => if(T == i8 ) return true else return false,
- c.DUCKDB_TYPE_SMALLINT => if(T == i16 ) return true else return false,
- c.DUCKDB_TYPE_INTEGER => if(T == i32 ) return true else return false,
- c.DUCKDB_TYPE_BIGINT => if(T == i64 ) return true else return false,
- c.DUCKDB_TYPE_UTINYINT => if(T == u8 ) return true else return false,
- c.DUCKDB_TYPE_USMALLINT => if(T == u16 ) return true else return false,
- c.DUCKDB_TYPE_UINTEGER => if(T == u32 ) return true else return false,
- c.DUCKDB_TYPE_UBIGINT => if(T == u64 ) return true else return false,
- c.DUCKDB_TYPE_FLOAT => if(T == f32 ) return true else return false,
- c.DUCKDB_TYPE_DOUBLE => if(T == f64 ) return true else return false,
- c.DUCKDB_TYPE_VARCHAR => if(T == []const u8) return true else return false,
- c.DUCKDB_TYPE_BLOB => if(T == []const u8) return true else return false,
- else => return false,
- }
-}
-
-/// Receives a pointer of the element (!)
-pub fn cast(el: anytype, T: type) !T {
- return switch (@typeInfo(T)) {
- .Bool, .Int, .Float => el.*,
- .Pointer => |p| switch (p.size) {
- .Slice => blk: {
- if ( p.child == u8 ) {
- var result: T = undefined;
- if (c.duckdb_string_is_inlined(el.*)){
- result = &el.value.inlined.inlined;
- result.len = el.value.inlined.length;
- break :blk result;
- } else {
- result.len = el.value.pointer.length;
- result.ptr = el.value.pointer.ptr;
- break :blk result;
- }
- } else {
- @compileError("Invalid type for output data");
- }
- },
- else => @compileError("Invalid type for output data")
- },
- else => @compileError("Invalid type for output data")
- };
-}