ortic/laravel-duckdb-pdo
Composer 安装命令:
composer require ortic/laravel-duckdb-pdo
包简介
DuckDB database driver for Laravel, backed by the native pdo_duckdb extension.
README 文档
README
A DuckDB database driver for Laravel, backed by the native
pdo_duckdb PHP extension.
DuckDB's SQL dialect is largely PostgreSQL-compatible, so this package extends
Laravel's Postgres query and schema grammars and adjusts the few places DuckDB
differs (auto-increment via sequences, CREATE [UNIQUE] INDEX instead of
ALTER TABLE ADD CONSTRAINT, no row-level locking, and information_schema
introspection).
An in-memory DuckDB is a fast, isolated database for tests; a file-backed DuckDB is a capable analytical store.
Status: early development, tracking the
pdo_duckdbextension.
Requirements
- PHP 8.2+ with the
pdo_duckdbextension installed and enabled. - Laravel 11 or 12 (
illuminate/database^11 | ^12).
Installation
composer require ortic/laravel-duckdb-pdo
The service provider is auto-discovered. It registers the duckdb database
driver.
This package requires the
pdo_duckdbextension (declared asext-pdo_duckdb), socomposer requirewill refuse to install until the extension is present in your runtime. See the DDEV section below to build it into a container.
DDEV
DDEV's web image doesn't ship pdo_duckdb, so it has to be compiled into the
container. Because a Composer package cannot install a PHP extension (and this
package won't even install without it), setting up the image is a bootstrap
step that runs before composer require.
Fetch the web-build Dockerfile straight from the extension repo and rebuild:
mkdir -p .ddev/web-build
curl -fsSL https://raw.githubusercontent.com/ortic/php-pdo-duckdb/main/examples/ddev/web-build/Dockerfile \
-o .ddev/web-build/Dockerfile
ddev restart # builds pdo_duckdb into the web image
ddev composer require ortic/laravel-duckdb-pdo
Once the package is installed, you can regenerate that Dockerfile any time with:
php artisan duckdb:install-ddev # --force to overwrite an existing one
(The artisan command is a convenience for re-scaffolding; the curl step above
is what bootstraps a project from scratch, since the extension must exist before
the package can be installed.)
Configuration
Add a connection to config/database.php:
'connections' => [ 'duckdb' => [ 'driver' => 'duckdb', 'database' => database_path('analytics.duckdb'), // or ':memory:' 'prefix' => '', // optional DuckDB config: // 'read_only' => false, // 'threads' => 4, // 'max_memory' => '4GB', ], ],
For an in-memory database use 'database' => ':memory:' (handy for the testing
connection in phpunit.xml).
Usage
Everything goes through the standard Laravel APIs:
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; Schema::connection('duckdb')->create('events', function ($table) { $table->id(); $table->string('name'); $table->timestamp('occurred_at'); }); DB::connection('duckdb')->table('events')->insert([ 'name' => 'signup', 'occurred_at' => now(), ]); $count = DB::connection('duckdb')->table('events')->count();
Eloquent works too — point a model at the connection:
class Event extends Model { protected $connection = 'duckdb'; }
What works
- Migrations & the schema builder: create/drop tables, columns, indexes and
unique indexes;
hasTable/hasColumn/getColumnListing. - Query builder: inserts (incl.
insertGetIdviaRETURNING), selects, wheres, ordering, aggregates, updates, deletes. - Transactions (
DB::transaction,beginTransaction/commit/rollBack). - Eloquent: create/find/update/delete, casts, query scopes.
DuckDB-specific notes
- Auto-increment (
$table->id(),increments()) is implemented with a DuckDB sequence plusDEFAULT nextval(...). As with Postgres sequences, ids consumed inside a rolled-back transaction are not reused. - Row locking (
lockForUpdate,sharedLock) compiles to nothing — DuckDB uses optimistic MVCC and has noSELECT ... FOR UPDATE. - Unique/index definitions become
CREATE [UNIQUE] INDEX; DuckDB does not support adding these viaALTER TABLE. - Booleans bound through untyped bindings follow the extension's rules — see the
pdo_duckdbnotes on parameter binding.
Running the tests
The suite spins up an in-memory DuckDB via Illuminate\Database\Capsule:
composer install php -d extension=pdo_duckdb vendor/bin/phpunit
(mbstring must be enabled — a standard Laravel requirement.)
License
MIT.
ortic/laravel-duckdb-pdo 适用场景与选型建议
ortic/laravel-duckdb-pdo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「pdo」 「laravel」 「duckdb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ortic/laravel-duckdb-pdo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ortic/laravel-duckdb-pdo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ortic/laravel-duckdb-pdo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
PHP module for MySql database
VV database abstraction layer with query builder and DB structure models
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-15