### ----------------------------------------------------
### -- Duckie
### -- Licenses: MIT
### -- Authors: Brian Duggan
### -- File: t/04-types.rakutest
### ----------------------------------------------------
use Test;
use Duckie::DuckDB::Native;
use NativeCall;

my $db-file will leave { .unlink if .IO.e } = $*TMPDIR.child('test.db');
my DuckDB::Native::Database $dbh .= new;
my DuckDB::Native::Connection $conn .= new;
my DuckDB::Native::Result $res .= new;

is duckdb_open($db-file.Str, $dbh), +DUCKDB_SUCCESS, 'open';
is duckdb_connect($dbh, $conn) , +DUCKDB_SUCCESS, 'connect';

is duckdb_query($conn, 'select * from test_all_types()', $res), +DUCKDB_SUCCESS, 'select';
ok $res.column_count >= 53, '>= 53 types in test';
my %types = DuckDBType.enums.invert.Hash;
for 0..52 {
  my $type = duckdb_column_type($res, $_);
  ok %types{ $type }:exists, "got column type '{ $type.raku }' : " ~ %types{ $type };
  ok $type.defined, "got column type '{ $type.raku }' : " ~ %types{ $type };
  my $logicaltype = duckdb_column_logical_type($res,$_);
  ok $logicaltype.defined, "got logical type too";
  ok do { duckdb_column_data($res, $_); 1 }, "column_data succeeded";
}

duckdb_destroy_result($res);

duckdb_disconnect($conn);
duckdb_close($dbh);

done-testing;


