Query Builder Import & Exports
Getting started
import { Database } from '@sluice/adbc';import SluiceDuckDBDialect, { KyselyDuckDB } from '@sluice/kysely-duckdb-adbc';
const adbc = new Database(':memory:');const db = new KyselyDuckDB({ dialect: new SluiceDuckDBDialect({ database: adbc }) });Import Tables
await db.importCSV('season', './fixtures/season.csv', { createTable: false, autoDetect: false, header: true, delimiter: '|', columns: { season: 'BIGINT', id: 'BIGINT', name: 'TEXT', start: 'TIMESTAMP', end: 'TIMESTAMP', years_start: 'BIGINT', years_end: 'BIGINT', created_date: 'TIMESTAMP', last_updated: 'TIMESTAMP', }, });await db.importJSON('season', './fixtures/season.json', { createTable: true, autoDetect: true, format: 'newline_delimited',});await db.importParquet('season', './fixtures/season.parquet', { createTable: true,});Export Tables
await db.exportCSV('season', './out/season.csv', { header: true, delimiter: '|',});await db.exportJSON('season', './out/season-out.ndjson', { timestampformat: '%c',});await db.exportParquet('season', './out/season.parquet');Export Database
// creates a copy as a single duckdb fileawait db.exportDuckDB('./out/export.duckdb');// creates a single sqlite file with all tablesawait db.exportSQLite('./out/export.sqlite');// exports all or specified tables to a hosted PostgreSQL instanceawait db.exportPostgreSQL('dbname=postgres user=postgres host=127.0.0.1');// imports all or specified tables from a MySQL instanceawait db.exportMySQL('host=localhost user=root port=0 database=mysql');// creates a folder with CSV files for each table, schema.sql and load.sqlawait db.exportDatabaseAsCSV('./out-folder-csv', { delimiter: '|' });// creates a folder with NDJSON files for each table, schema.sql and load.sqlawait db.exportDatabaseAsJSON('./out-folder-json');// creates a folder with parquet files for each table, schema.sql and load.sqlawait db.exportDatabaseAsParquet('./out-folder-parquet');Import Database
// imports all or specified tables from a duckdb fileawait db.importDuckDB('./out/import.duckdb', { tables: ['season'] });// imports all or specified tables from a duckdb fileawait db.importSQLite('./out/import.sqlite', { tables: ['season'] });// imports all or specified tables from a PostgreSQL instanceawait db.importPostgreSQL('dbname=postgres user=postgres host=127.0.0.1');// imports all or specified tables from a MySQL instanceawait db.importMySQL('host=localhost user=root port=0 database=mysql');// NOT CURRENTLY WORKING IN DUCKDB C DRIVER 0.10.0// imports from a folder with CSV files for each table, schema.sql and load.sql awaitdb.importDatabaseFromFolder('./path-to-folder');// NOT CURRENTLY WORKING IN DUCKDB C DRIVER 0.10.0// creates a folder with NDJSON files for each table, schema.sql and load.sql awaitdb.importDatabaseFromFolder('./path-to-folder');// NOT CURRENTLY WORKING IN DUCKDB C DRIVER 0.10.0// creates a folder with parquet files for each table, schema.sql and load.sql awaitdb.importDatabaseFromFolder('./path-to-folder');