PHPackages                             thomas-0816/doctrine-dbal-duckdb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. thomas-0816/doctrine-dbal-duckdb

ActiveLibrary[Database &amp; ORM](/categories/database)

thomas-0816/doctrine-dbal-duckdb
================================

Doctrine DBAL for DuckDB, powered by the PHP PDO Driver for DuckDB

067↑2631.3%PHPCI passing

Since Aug 14Pushed todayCompare

[ Source](https://github.com/thomas-0816/doctrine-dbal-duckdb)[ Packagist](https://packagist.org/packages/thomas-0816/doctrine-dbal-duckdb)[ RSS](/packages/thomas-0816-doctrine-dbal-duckdb/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Doctrine DBAL for DuckDB
========================

[](#doctrine-dbal-for-duckdb)

A [DuckDB](https://duckdb.org) database driver for Doctrine DBAL powered by the DuckDB PDO Driver.

Integrates DuckDB's analytical database engine into Doctrine, enabling fast analytical queries directly in your Symfony application.

[![logo](logo.jpg?1)](logo.jpg?1)

Requirements
------------

[](#requirements)

- PHP 8.2+
- Doctrine DBAL 4+
- Symfony 7+
- pdo\_duckdb PHP extension

Install and setup
-----------------

[](#install-and-setup)

Install and setup [pdo\_duckdb](https://github.com/thomas-0816/pdo-duckdb-php) database driver with [PIE](https://github.com/php/pie):

```
pie install thomas-0816/pdo-duckdb-php
```

Install and setup Doctrine DBAL for DuckDB:

```
composer require thomas-0816/doctrine-dbal-duckdb
```

`pdo_duckdb` is a native DuckDB database driver for the PHP Data Objects (PDO) interface.
As a native PHP extension, it is implemented in C/C++ and does not require PHP FFI or preloading.
It is also thread safe and fully tested with FrankenPHP (PHP-ZTS).
The release packages contain pre-compiled binaries for all supported platforms and DuckDB is directly included.
DuckDB extensions work the same way as they do in DuckDB CLI.

Configuration
-------------

[](#configuration)

change `.env`

```
DATABASE_URL="duckdb://_/%kernel.project_dir%/var/db.duckdb"
```

change `config/packages/doctrine.yaml`

```
doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        driver_schemes:
            duckdb: DuckDb\DBAL\Driver
        options:
            !php/const PDO::DUCKDB_ATTR_CONFIG:
                TimeZone: 'Europe/Berlin'
                # threads: 4 # max. number of threads
                # memory_limit: '4GB' # max. memory usage
                # access_mode: 'read_only' # open database file read-only
    orm:
        identity_generation_preferences:
            DuckDb\DBAL\Platforms\DuckDBPlatform: sequence
```

after changing doctrine.yaml, clear the cache:

```
rm -rf var/cache
```

Connection test:

```
php bin/console dbal:run-sql 'SELECT version()'
```

In-Memory Database
------------------

[](#in-memory-database)

For testing or reading external files, use the special in-memory database in `.env`:

```
DATABASE_URL="duckdb::memory:"
```

ORM Usage
---------

[](#orm-usage)

Create a new entity `Product` with attributes `name` (string) and `price` (float):

```
echo -e "name\nstring\n\n\nprice\nfloat\n\n\n" | php bin/console make:entity Product

# php bin/console make:migration
# php bin/console doctrine:migrations:migrate -vv
```

Create a new Product:

```
$product = new Product();
$product->setName('foo');
$product->setPrice(12.34);
$entityManager->persist($product);
$entityManager->flush();
```

Query, update and delete a Product:

```
$repository = $entityManager->getRepository(Product::class);
$product = $repository->findOneBy(['name' => 'foo']);
$product->setName('bar');
$entityManager->flush();

dump($repository->findOneBy(['name' => 'bar']));

# App\Entity\Product
#   -id: 1
#   -name: "bar"
#   -price: 12.34
# }

$entityManager->remove($product);
$entityManager->flush();

dump($product = $repository->findOneBy(['name' => 'bar']));
# null
```

Select with Doctrine Query Language
-----------------------------------

[](#select-with-doctrine-query-language)

```
$query = $entityManager->createQuery("
    SELECT p
    FROM App\Entity\Product p
    WHERE p.name = :name
")->setParameter('name', 'foo');

dump($query->getResult());

# array
#   App\Entity\Product
#     -id: 1
#     -name: "foo"
#     -price: 12.34
```

Select with Query Builder
-------------------------

[](#select-with-query-builder)

```
$query = $entityManager->createQueryBuilder()
    ->select('p')
    ->from(Product::class, 'p')
    ->where('p.name = :name')
    ->setParameter('name', 'foo')
    ->getQuery();
dump($query->execute());

# array
#   App\Entity\Product
#     -id: 1
#     -name: "foo"
#     -price: 12.34
```

Select with SQL
---------------

[](#select-with-sql)

```
$sql = '
    SELECT *
    FROM product
    WHERE name = :name
';
$result = $entityManager->getConnection()->executeQuery($sql, ['name' => 'foo']);
dump($result->fetchAllAssociative());

# array
#   array
#     "id" => 1
#     "name" => "foo"
#     "price" => 12.34
```

work in progress ...
--------------------

[](#work-in-progress-)

Performance
-----------

[](#performance)

DuckDB is extremely fast when it comes to analytic queries.
Here is an example with 10M rows, performing in **170ms on 4 threads with 128M ram**:

```
.timer on
/* generate 10M rows with random data */
COPY (
    SELECT i,
        (random()*1_000)::decimal(11,2) as d1,
        (random()*1_000)::int as i1,
        to_hex((random()*100000)::int) as h1,
        to_timestamp((i+1_0000_000) * random() * 100)::timestamp as created
    FROM generate_series(10_000_000) s(i)
) TO '/tmp/test.parquet' (format parquet, compression zstd);
/* Run Time (s): real 4.158 user 4.002094 sys 0.154674 */

SET threads = 4;
SET memory_limit = '128M';
SELECT count(*), sum(i), avg(d1), stddev(i1), avg(length(h1)), avg(date_diff('day', current_date, created))
FROM '/tmp/test.parquet';
/* Run Time (s): real 0.170 user 0.616465 sys 0.051658 */
```

Security
--------

[](#security)

Use SQL `SET variable = value;` or put the settings inside the PDO::DUCKDB\_ATTR\_CONFIG connection [options array](#Configuration):

```
# Disable extension loading
SET autoload_known_extensions = false;
SET autoinstall_known_extensions = false;
SET allow_community_extensions = false;

# Disable external file access, directory white listing
SET allowed_directories = ['/tmp'];
SET enable_external_access = false;

# Resource limits
SET threads = 4;
SET memory_limit = '4GB';
SET max_temp_directory_size = '4GB';

# Lock configuration
SET lock_configuration = true;
```

A complete list is available in the DuckDB documentation: [Securing DuckDB](https://duckdb.org/docs/lts/operations_manual/securing_duckdb/overview).

Development
-----------

[](#development)

```
# testing
composer test
composer test_fix
./vendor/bin/phpunit --coverage-text
```

Why DuckDB?
-----------

[](#why-duckdb)

In-Process Architecture: Like SQLite, DuckDB embeds directly into host applications, eliminating the need for a separate server setup.

Extreme Analytical Speed: It uses columnar storage and vectorized (batch) processing, running analytics 10–100x faster than traditional row-oriented databases.

"Larger-than-Memory" Processing: DuckDB gracefully spills data to disk, allowing you to process massive datasets (e.g., 50GB+) on a machine with minimal RAM (e.g., 1GB).

File-Format Agnostic: It can query flat files (JSON, CSV, and Parquet) directly via SQL without needing to import or load the data into a database first.

No Infrastructure Cost: It brings data warehouse-level performance to your local laptop or local server.

DuckDB achieves blazing-fast analytical performance through its **embedded, serverless multi-core** architecture combined with columnar storage and vectorized execution. By executing queries directly within the host application, it eliminates serialization and network overhead, processing data in batches (vectors) rather than row-by-row for unparalleled speed.

[https://duckdb.org/why\_duckdb](https://duckdb.org/why_duckdb)

Key Performance Advantages:

Vectorized Query Execution: Unlike row-oriented engines, DuckDB processes data in cache-friendly batches (vectors). This allows modern hardware to operate on entire arrays of data simultaneously, drastically reducing CPU cycles per query.

Columnar Storage: Data is stored by column rather than by row. For analytical queries that only require a few metrics, DuckDB only reads the relevant columns from disk/memory, saving massive amounts of I/O.

Zero-Copy In-Process Engine: As an in-process database, DuckDB runs directly in the memory space of your application.

Advanced Query Optimizer: DuckDB features an advanced query optimizer that handles filter pushdowns, unnesting of subqueries, and dynamic runtime filters. This ensures queries only scan necessary data and avoids full-table sorting when possible.

Direct File Querying: You can query large datasets in open formats like Parquet and CSV directly on disk or in cloud storage (like AWS S3) without needing to import or convert the data first.

FAQ
---

[](#faq)

> Do I need an extra server for DuckDB?

No. DuckDB runs completely embedded inside of PHP as an extension, just like SQLite.

> How much RAM and CPU do I need for DuckDB?

DuckDB normally runs good with 1-4 GB RAM and 2-4 CPU cores.

> How good is the compression with Parquet and zstd?

For logs you normally achieve compression rates of 50-100x.

> Who is maintaining DuckDB?

The DuckDB project is owned and maintained by the [DuckDB Foundation](https://duckdb.foundation), a non-profit organization from Amsterdam.

> Can I get commercial support for DuckDB?

Yes. Commercial support is available from [DuckLabs](https://ducklabs.com), a company based in Amsterdam.

> Can I get free support for DuckDB?

Yes. Free support is available on GitHub and Discord, see the [support policy](https://ducklabs.com/community_support_policy/) for details.
You can meet the core team in-person on community events, meetup, conferences, etc.

> Is the Doctrine DBAL driver for DuckDB developed by the DuckDB project?

No. This is a third-party open-source community project.

> Is DuckDB fully open-source?

Yes. DuckDB and all components are fully open-source under the MIT license.
There is no “enterprise version” of DuckDB.

AI Disclosure
-------------

[](#ai-disclosure)

The code is written by AI, reviewed and tested without AI.

License
-------

[](#license)

MIT License

###  Health Score

24

—

LowBetter than 30% of packages

Maintenance65

Regular maintenance activity

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2d76ab33e3380db92d1488fbce154b710a4f0795eb337f46cfc2596b588d41a?d=identicon)[thomas-0816](/maintainers/thomas-0816)

---

Top Contributors

[![thomas-0816](https://avatars.githubusercontent.com/u/941223?v=4)](https://github.com/thomas-0816 "thomas-0816 (150 commits)")

---

Tags

analyticsdoctrinedoctrine-dbalduckdbpdophp

### Embed Badge

![Health badge](/badges/thomas-0816-doctrine-dbal-duckdb/health.svg)

```
[![Health](https://phpackages.com/badges/thomas-0816-doctrine-dbal-duckdb/health.svg)](https://phpackages.com/packages/thomas-0816-doctrine-dbal-duckdb)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2920.0k](/packages/voku-session2db)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
