SQL module
Query databases through the source contract.
SQL data sources expose database metadata and query results through the loaders.gl source API. Applications can request ordinary object rows or a typed Arrow table without changing the surrounding data flow.
The SQL source boundary
Discover the database. Submit a query. Return a common table.
The source owns adapter-specific connection and metadata behavior, while application code consumes a small set of query and discovery methods.
Adapters
DuckDB local/wasm and Snowflake SQL API
Discover
Catalogs, schemas, tables, and capabilities
Query
SQL text with adapter-specific options
Output
Object rows or Arrow table data
Detailed guide
Source methods
The reference below covers available adapters, metadata discovery, row queries, Arrow queries, and environment-specific requirements.
SQL data sources provide createDataSource() integration for external and embedded databases.
Sources
DuckDBSQLSourceconnects to local DuckDB databases in Node.js and DuckDB wasm in the browser.SnowflakeSQLSourceconnects to Snowflake through the SQL API.
Core methods
queryRows(sqlText, options)returns object rows.queryArrow(sqlText, options)returns an Apache ArrowTable.getMetadata()returns catalogs, schemas, tables, and adapter capabilities.
DuckDB Arrow interoperability
The browser adapter exchanges Arrow IPC bytes with DuckDB-Wasm. DuckDB retains its Arrow 17 dependency; loaders.gl decodes query results with Arrow 21. Do not force DuckDB's Arrow dependency to a different major through package-manager resolutions or bundler deduplication. IPC results are materialized in memory before decoding.
DuckDBSQLDataSource.insertArrowTable(table, options) uploads an Apache Arrow
Table by serializing it as an IPC stream. options.tableName identifies the
destination, schemaName optionally selects a schema, and create defaults to
true. Set create: false to append to an existing table. Uploads currently
require the browser DuckDB-Wasm adapter; the Node adapter reports an unsupported
operation. insertArrowIPC(bytes, options) also accepts an already serialized IPC stream.
Custom adapters can implement insertArrowIPC(bytes, options).
await source.insertArrowTable(arrowTable, {tableName: 'events'});
await source.insertArrowTable(moreEvents, {tableName: 'events', create: false});
const result = await source.queryArrow('SELECT * FROM events');
Sources and credits
See the package source and license inventory and the project-wide Attributions and Credits.
Common queries on DuckDB tables
Resolve a DuckDB table once with await source.getTable(name) and pass the handle as
source to query or queryInBatches from @loaders.gl/core/query. You can also
use a structured from: {source, table} reference with a registered DuckDB source.
Reuse the table handle for adjacent pages to avoid repeating schema and table discovery.
For base tables with an accessible DuckDB rowid, the reader uses row ID order and
passes OFFSET and LIMIT into SQL. Page boundaries assume the underlying table
stays unchanged between calls. Deep offsets can still cost work inside DuckDB.
The planner accepts signed integer identity and widening casts that preserve Arrow semantics. Other casts run in Arrow. For example, Arrow truncates fractional values when casting to integers, while DuckDB can round them. The common reader currently supports signed integer, floating-point, Boolean, and VARCHAR columns.
DuckDB also pushes down signed integer casts to DOUBLE PRECISION for input widths up to 32 bits,
whose full range is exactly representable. In a mixed projection, a safe cast can run
in DuckDB while other SELECT expressions run in Arrow on the same filtered and paged rows.