PHPackages                             filipefernandes/laravel-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. filipefernandes/laravel-duckdb

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

filipefernandes/laravel-duckdb
==============================

A Laravel database driver for DuckDB.

1.1.0(1mo ago)516MITPHPPHP ^8.2

Since Dec 26Pushed 1mo agoCompare

[ Source](https://github.com/filipefernandes9747/laravel-duckdb)[ Packagist](https://packagist.org/packages/filipefernandes/laravel-duckdb)[ RSS](/packages/filipefernandes-laravel-duckdb/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (4)Used By (0)

[![Thumbnail](assets/thumbnail.png)](assets/thumbnail.png)

Laravel DuckDB Driver
=====================

[](#laravel-duckdb-driver)

A production-ready Laravel database driver for DuckDB, powered by `satur/duckdb-auto`. This package allows you to query DuckDB databases using Laravel's powerful Query Builder for analytical (OLAP) workloads.

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

[](#requirements)

- PHP 8.2+
- Laravel 10.0+ or 11.0+
- **FFI Extension Enabled** (`ffi.enable=true` or `preload` in `php.ini`)

Warning

**Production Notice**: Enabling FFI globally (`ffi.enable=true`) can have security implications. It is recommended to use `ffi.enable=preload` in production environments and preload the necessary scripts if possible, or strictly control access to the server.

Installation
------------

[](#installation)

1. Install via Composer:

```
composer require filipefernandes/laravel-duckdb
```

2. Configuration

Add the connection configuration to your `config/database.php` file:

```
'connections' => [

    'duckdb' => [
        'driver' => 'duckdb',
        'database' => env('DUCKDB_DB_FILE', storage_path('duckdb/analytics.db')),
        'prefix' => '',
        'read_only' => false,
    ],

],
```

Auto-Installer
--------------

[](#auto-installer)

This package automatically downloads and installs the DuckDB native binary and FFI header when your application boots — **no manual setup required**.

On first boot it will:

1. Create `storage/duckdb/` (if it doesn't exist)
2. Download the correct native library for your OS from the [DuckDB GitHub Releases](https://github.com/duckdb/duckdb/releases)
3. Download the `duckdb.h` FFI header
4. Set the required environment variables (`DUCKDB_LIB_PATH`, `DUCKDB_HEADER_PATH`) at runtime

Subsequent boots detect the files are already present and **skip the download** (idempotent).

### Supported platforms

[](#supported-platforms)

OSArchitectureLibraryWindowsx86\_64`duckdb.dll`Linuxx86\_64`libduckdb.so`Linuxaarch64`libduckdb.so`macOSUniversal`libduckdb.dylib`### Configuration

[](#configuration)

Publish the config file to override defaults:

```
php artisan vendor:publish --tag=duckdb-config
```

Available `.env` variables:

```
DUCKDB_AUTO_INSTALL=true          # Set to false to disable auto-installer
DUCKDB_INSTALL_PATH=/custom/path  # Override install directory (default: storage/duckdb)
DUCKDB_VERSION=1.2.1              # Pin a specific DuckDB release version
```

Note

`ext-zip` must be enabled in your `php.ini` (it is bundled with PHP by default on most platforms). If the installer fails (e.g. no internet access), it logs the error and **does not crash the application** — allowing you to manage binaries manually.

Usage
-----

[](#usage)

You can use the `DB` facade to interact with DuckDB.

### Querying Files

[](#querying-files)

You can query files directly (Parquet, CSV, JSON) without pre-configuring tables using the `file()` helper:

```
use Illuminate\Support\Facades\DB;

// Query a Parquet file
$users = DB::connection('duckdb')
    ->file('storage/app/data.parquet')
    ->where('age', '>', 25)
    ->get();

// Or get all records from a file
$allUsers = DB::connection('duckdb')->all('storage/app/data.parquet');

// Print formatted output (useful for debugging)
DB::connection('duckdb')->print("SELECT * FROM 'storage/app/data.parquet' LIMIT 10");

// Or chain print() on a query builder
DB::connection('duckdb')->file('storage/app/data.parquet')->print();

// Insert a single row into a file
DB::connection('duckdb')->create('storage/app/data.parquet', [
    'id' => 1,
    'name' => 'John Doe',
    'email' => 'john@example.com'
]);

// Insert multiple rows into a file
DB::connection('duckdb')->insertInto('storage/app/data.parquet', [
    ['id' => 1, 'name' => 'John', 'email' => 'john@example.com'],
    ['id' => 2, 'name' => 'Jane', 'email' => 'jane@example.com'],
]);
```

### Basic Queries

[](#basic-queries)

```
use Illuminate\Support\Facades\DB;

// Select all users
$users = DB::connection('duckdb')->table('users')->get();

// Aggegrations
$count = DB::connection('duckdb')->table('events')->count();
```

### Analytical Queries (OLAP)

[](#analytical-queries-olap)

DuckDB shines at analytics. You can query Parquet, CSV, or JSON files directly.

```
// Querying a Parquet file directly
$results = DB::connection('duckdb')
    ->select("SELECT * FROM 'path/to/data.parquet' LIMIT 10");

### Examples

```php
use Illuminate\Support\Facades\DB;

// 1. Get all users
$users = DB::connection('duckdb')->table('users')->get();

// 2. Aggregate count
$count = DB::connection('duckdb')->table('users')->count();

// 3. Conditional Fetch with Bindings
$user = DB::connection('duckdb')
    ->table('users')
    ->where('id', 1)
    ->first();

// 4. Raw SQL Select
$results = DB::connection('duckdb')->select("SELECT * FROM users WHERE email LIKE ?", ['%example.com']);

// 5. Analytical Query (DuckDB syntax)
// e.g. Extract hour from timestamp
$hourly = DB::connection('duckdb')
    ->select("SELECT date_part('hour', created_at) as hour, count(*) as count FROM users GROUP BY 1");
```

### Limitations

[](#limitations)

- **No Eloquent Support**: This driver is designed for **read-heavy analytical workloads**. Eloquent ORM features (Models, Relationships, saving models) are **not supported** and usually incompatible with DuckDB's constraints and lack of certain OLTP features. Use the Query Builder.
- **Transactions**: DuckDB handles transactions differently. Nested transactions or complex locking expected by standard Laravel apps might not work as intended.
- **FFI Binding Interpolation**: Due to the nature of the FFI integration, prepared statements with placeholders are emulated by valid string interpolation within the driver. Use caution with raw queries.

Security
--------

[](#security)

Ensure your `php.ini` has FFI enabled:

```
[ffi]
ffi.enable=true
```

Testing
-------

[](#testing)

To run the test suite, make sure you have installed the dependencies:

```
composer install
```

Then run PHPUnit:

```
vendor/bin/phpunit
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance90

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~45 days

Total

3

Last Release

47d ago

Major Versions

0.0.1 → 1.0.02026-03-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/44c4a0ab684a6ff2f571c5b6b1db79320570f053120dadb2793c9b8ee41529a3?d=identicon)[filipe9747](/maintainers/filipe9747)

---

Top Contributors

[![ffernandes9747](https://avatars.githubusercontent.com/u/106343739?v=4)](https://github.com/ffernandes9747 "ffernandes9747 (9 commits)")

---

Tags

laraveldatabasedriverffiduckdbolap

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/filipefernandes-laravel-duckdb/health.svg)

```
[![Health](https://phpackages.com/badges/filipefernandes-laravel-duckdb/health.svg)](https://phpackages.com/packages/filipefernandes-laravel-duckdb)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[dbt/odbc-driver

ODBC Driver for Laravel 12+

28137.1k](/packages/dbt-odbc-driver)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)

PHPackages © 2026

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