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

my $db-file will leave { .unlink if .IO.e } = $*TMPDIR.child('test.db');
my $csv-dir = $*PROGRAM.parent.child('csv');

my DuckDB::Native::Database $dbh .= new;
my DuckDB::Native::Connection $conn .= new;
my DuckDB::Native::Result $res .= new;

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

is duckdb_query($conn, "select * from '{$csv-dir.child('imdb.csv')}' limit 10", $res), +DUCKDB_SUCCESS, 'select from csv';
is duckdb_column_count($res), 5, '5 columns';
is duckdb_row_count($res), 10, '10 rows';

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


