NAME

DBD::D1 - DBI driver for Cloudflare D1 (serverless SQLite)

VERSION

0.02

SYNOPSIS

use DBI;

my $dbh = DBI->connect(
    'dbi:D1:account_id=<ACCOUNT_ID>;database_id=<DATABASE_ID>',
    undef,
    $ENV{CF_API_TOKEN},
    { RaiseError => 1, PrintError => 0 },
) or die $DBI::errstr;

my $sth = $dbh->prepare('SELECT * FROM users WHERE active = ?');
$sth->execute(1);

while (my $row = $sth->fetchrow_hashref) {
    printf "%s <%s>\n", $row->{name}, $row->{email};
}

$dbh->disconnect;

DESCRIPTION

DBD::D1 is a DBI driver for Cloudflare D1, Cloudflare's serverless SQLite-compatible relational database.

It communicates via the D1 REST API using HTTP::Tiny and JSON::PP (both ship with Perl 5.14+), so no compiled extensions are required.

DSN FORMAT

dbi:D1:account_id=<ACCOUNT_ID>;database_id=<DATABASE_ID>

AUTHENTICATION

Pass your Cloudflare API token (D1 Edit permission) as the $password argument to DBI->connect().

LIMITATIONS

  • AutoCommit only – D1 REST has no multi-statement transaction support.

  • Column ordering – rows arrive as JSON objects; column order follows sort on key names. Use fetchrow_hashref for reliable named access.

DEPENDENCIES

DBI, HTTP::Tiny, JSON::PP, IO::Socket::SSL, Net::SSLeay

AUTHOR

Aldo Montes Zapata, <amontes@cpan.org>

COPYRIGHT (c)

Copyright 2026 by Aldo Montes Zapata <amontes@cpan.org>.

LICENSE

Same terms as Perl itself.