DBIO::DuckDB
DuckDB driver for DBIO (modern embedded analytical database).
Supports
- desired-state deployment via test-deploy-and-compare (DBIO::DuckDB::Deploy)
- native introspection (DBIO::DuckDB::Introspect)
- native diff (DBIO::DuckDB::Diff)
- native DDL generation (DBIO::DuckDB::DDL)
- Quack client-server RPC (libduckdb >= 1.5):
quack_serve,quack_attach,quack_detach
Usage
package MyApp::DB;
use base 'DBIO::Schema';
__PACKAGE__->load_components('DuckDB');
my $schema = MyApp::DB->connect('dbi:duckdb:myapp.db');
For in-memory database:
my $schema = MyApp::DB->connect('dbi:duckdb:');
DBIO core autodetects dbi:duckdb: DSNs and loads this storage automatically.
DuckDB Features
Types
INTEGER,BIGINT,SMALLINT,TINYINT- signed integersUINTEGER,UBIGINT,USMALLINT,UTINYINT- unsigned integersFLOAT,DOUBLE,DECIMAL- numeric typesVARCHAR,CHAR,TEXT- string typesBLOB- binary dataDATE,TIME,TIMESTAMP,TIMESTAMP WITH TIME ZONE- temporal typesINTERVAL- time intervalsJSON/JSONB- JSON data (stored as VARCHAR but with JSON operators)ARRAY,STRUCT,MAP- complex typesHUGEINT- 128-bit integerBIT- fixed-length bit string
Arrow Integration
- Direct import/export of Apache Arrow tables
duckdb_append_arrowfor high-speed data ingestion- Read from and write to Parquet files directly via SQL
Parquet Support
SELECT * FROM 'file.parquet'- read Parquet files as tablesCOPY ... TO 'file.parquet' (FORMAT PARQUET)- export to Parquet- Automatic Parquet file detection and reading
- Directory-based Parquet tables (read all files in folder)
DuckDB-Specific Features
INSERT ... ON CONFLICT ... DO UPDATE(upsert)RETURNINGclause for all INSERT/UPDATE/DELETECOPY ... FROM STDINfor bulk import (CSV, Parquet, JSON)SUMMARIZEfor automatic statistics on tablesEXPORT DATABASEto recreate schema and dataIMPORT DATABASEto load exported data- In-database LLM support via
ai_hint_create/ai_query
Introspection
duckdb_tables()information schema functionduckdb_columns()for column metadataduckdb_indexes()for index informationduckdb_constraints()for constraint details
Deploy
DBIO::DuckDB::Deploy orchestrates test-deploy-and-compare:
- Introspect live database via DuckDB information schema (DBIO::DuckDB::Introspect)
- Deploy desired schema to a temporary in-memory database
- Introspect the temporary database the same way
- Diff source vs target (DBIO::DuckDB::Diff)
DuckDB's speed makes deploy-and-compare very fast even for large schemas.
Install (install_ddl) creates fresh schema. Upgrade diffs live vs. desired.
Testing
export DBIO_TEST_DUCKDB_DSN="dbi:duckdb:"
prove -l t/
DuckDB in-memory mode requires no external process - perfect for testing.
Requirements
- Perl 5.36+
- DBD::DuckDB
- DBIO core
See Also
DBIO::Introspect::Base, DBIO::Diff::Base, DBIO::Deploy