定制 ortic/laravel-duckdb-pdo 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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_duckdb extension.

Requirements

  • PHP 8.2+ with the pdo_duckdb extension 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_duckdb extension (declared as ext-pdo_duckdb), so composer require will 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. insertGetId via RETURNING), 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 plus DEFAULT 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 no SELECT ... FOR UPDATE.
  • Unique/index definitions become CREATE [UNIQUE] INDEX; DuckDB does not support adding these via ALTER TABLE.
  • Booleans bound through untyped bindings follow the extension's rules — see the pdo_duckdb notes 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 ortic/laravel-duckdb-pdo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-15