Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Cloudflare D1 Database

Cloudflare D1 Database Laravel Package

ntanduy/cloudflare-d1-database

Use Cloudflare D1 as a native Laravel database driver with full Eloquent ORM, Query Builder, and migration support. Choose REST API or Worker connections, batch queries, bulk inserts, read replication, import and schema dump commands, time travel, retries, and circuit breaking. Requires PHP 8.2+ and...

View on GitHub
Deep Wiki
Context7

Cloudflare D1 database driver for Laravel — full Eloquent & Query Builder support.

Frequently asked questions about Cloudflare D1 Database
How do I install and configure this package for Laravel?
Run `composer require ntanduy/cloudflare-d1-database`, then add the D1 connection to your `.env` with `D1_DATABASE_ID` and `D1_ACCOUNT_ID`. Configure the connection in `config/database.php` under `connections.d1`. For Worker mode, also set `D1_WORKER_URL` and `D1_WORKER_HMAC_SECRET`.
Does this package support Laravel Eloquent models and migrations?
Yes, it fully supports Eloquent ORM and Query Builder. Migrations work, but rollbacks are unsupported due to D1’s immutable design. Use `php artisan d1:schema-dump` to export your schema for version control.
What Laravel versions are supported, and is PHP 8.1 compatible?
This package supports Laravel 10–13.x and requires PHP 8.2+. PHP 8.1 or lower is not supported due to dependency requirements.
How do I choose between REST and Worker drivers?
Use the REST driver for simplicity in development or low-throughput apps. For production with low-latency needs, deploy the Worker driver (requires a Cloudflare Worker). Worker mode also enables read replicas and auto read/write splitting.
Can I use D1 for complex transactions or multi-statement queries?
D1 lacks traditional ACID transactions. Use batch queries for atomicity, but avoid multi-statement transactions. For critical operations, consider a hybrid approach (e.g., D1 for reads, PostgreSQL for writes).
How do I handle D1’s SQL limitations, like no LIMIT in UPDATE statements?
Workarounds include using Common Table Expressions (CTEs) with `WITH` clauses or restructuring queries. The package documentation provides examples for common limitations. Test edge cases early in your migration.
Is there a way to mock D1 interactions in PHPUnit tests?
Yes, the package uses Saloon HTTP clients, which can be mocked with PHPUnit. For D1-specific behavior (e.g., batch queries), create custom test doubles or use the `DatabaseMocker` trait provided in the package.
How do I import an existing database schema into D1?
Use the `php artisan d1:import` command to import SQL files. For large datasets, consider breaking the import into smaller batches or using the `d1:time-travel` command to restore from a dump.
What are the costs associated with using Cloudflare D1?
D1 offers a free tier with 1GB storage and 100MB/day compute. Monitor usage in staging to avoid exceeding limits. Production workloads may incur costs based on storage and compute usage.
Are there alternatives if I need full transaction support?
If transactions are critical, consider using a traditional database like PostgreSQL or MySQL alongside D1. For read-heavy workloads, D1 can serve as a global cache layer while PostgreSQL handles writes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/command-executor-lib
tagixo/document-builder
tagixo/page-builder
tagixo/mail-builder
tagixo/form-builder
primix/primix
tagixo/core
alesima/laravel-azure-service-bus
tomshaw/shopcart
likyly/laravel
darthsoup/shoppingcart
tdt/core
labyrinthe/connect-php
encore2/laravel-admin2
cboxdk/laravel-console-kit
shapecode/doctrine-dbal-datetimeutc
gilads-otiannoh254/inertia-protocol
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite