Databases
Serverless SQLite
A SQLite database behind one HTTPS endpoint. Use it from Node, Python, Django, or plain HTTP.
Each database has its own HTTPS endpoint. Every statement is one request to it, authenticated with an API key. There is no server to run.
The endpoint
The database’s address is on its overview page in the dashboard:
https://<id>-sqlite.dcubix.cloudSend the API key as a Bearer token:
Authorization: Bearer <api key>The examples below read the address and key from DCX_DB_URL and DCX_DB_KEY.
Node.js, Bun and Deno
npm install @dcubix/sqliteimport { connect } from '@dcubix/sqlite'
const db = connect({
url: process.env.DCX_DB_URL,
token: process.env.DCX_DB_KEY,
})
const { results } = await db
.prepare('SELECT * FROM users WHERE id = ?')
.bind(1)
.all()connect() returns the same interface as a Cloudflare D1 binding, so code written for D1 works unchanged. It needs only fetch: Node.js 18 or later, Bun, Deno, or a Worker. The package is ESM; require() loads it on Node.js 20.19 or later.
With an ORM
Pass it to the ORM’s D1 driver:
// Drizzle
import { drizzle } from 'drizzle-orm/d1'
import { migrate } from 'drizzle-orm/d1/migrator'
const orm = drizzle(connect({ url, token }))
await migrate(orm, { migrationsFolder: './drizzle' })// Kysely
import { Kysely } from 'kysely'
import { D1Dialect } from 'kysely-d1'
const orm = new Kysely<Database>({
dialect: new D1Dialect({ database: connect({ url, token }) }),
})What it supports
| Method | |
|---|---|
prepare(sql), .bind(...values) |
Yes. bind() returns a new statement |
.all(), .run(), .raw(), .first() |
Yes |
batch([...statements]) |
Yes, as one transaction |
exec(sql) |
Yes, one statement per line |
withSession() |
Not yet |
dump() |
No |
Python
pip install dcubix-sqliteThe driver follows Python’s sqlite3 module: ? placeholders, description, rowcount, lastrowid and the same exception classes. It is pure Python with no dependencies.
import os
import dcubix_sqlite
conn = dcubix_sqlite.connect(
url=os.environ["DCX_DB_URL"],
token=os.environ["DCX_DB_KEY"],
)
conn.execute("INSERT INTO users (email) VALUES (?)", ("a@example.com",))
row = conn.execute(
"SELECT id, email FROM users WHERE email = ?", ("a@example.com",)
).fetchone()A connection can be shared between threads; a cursor can’t. Named parameters (:name) are not supported.
Django
The same package includes a Django database backend, for Django 5.2 and 6.x:
DATABASES = {
"default": {
"ENGINE": "dcubix_sqlite.django",
"URL": os.environ["DCX_DB_URL"],
"TOKEN": os.environ["DCX_DB_KEY"],
}
}It is Django’s SQLite backend with the database across the network: the same SQL, field types and migrations. Migrations made against SQLite on your machine run unchanged with python manage.py migrate. A common setup keeps a local SQLite file in development:
if os.environ.get("DCX_DB_URL"):
DATABASES = {
"default": {
"ENGINE": "dcubix_sqlite.django",
"URL": os.environ["DCX_DB_URL"],
"TOKEN": os.environ["DCX_DB_KEY"],
}
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}OPTIONS takes timeout, in seconds, for each request. The default is 60.
What differs from SQLite on your machine
-
Every statement commits on its own.
transaction.atomic()runs, but can’t roll back. Writes that must apply together go in one batch, which runs as one transaction:Pythonfrom dcubix_sqlite.django import batch batch([ ("UPDATE accounts SET balance = balance - %s WHERE id = %s", [100, 1]), ("UPDATE accounts SET balance = balance + %s WHERE id = %s", [100, 2]), ]) -
Migrations apply whole or not at all. Each one is sent as a single batch.
-
Every query is a request, from a few tens of milliseconds to a couple of hundred depending on distance. Use
select_related()andprefetch_related()to avoid one query per row. -
Time zones without daylight saving only. Date functions work in UTC and in zones such as Asia/Kolkata or Asia/Singapore. A zone with daylight saving, such as Europe/London, raises
NotSupportedError; setTIME_ZONE = "UTC"and convert for display. -
Integers beyond ±9,007,199,254,740,991 come back rounded. Store 64-bit IDs, such as Discord or Twitter IDs, in a
CharField. -
Not available: the
__regexand__iregexlookups,MD5(), theSHA…()functions,Reverse(),StdDev(),Variance(), theBit…()aggregates,AnyValue(),UUID4(),UUID7()andmanage.py dbshell. -
Fixtures load in order: an object must come before the objects that point to it.
-
Tests need a database of their own, set under
TESTwith its ownURLandTOKEN. Its tables are dropped before and after the run. Running tests against a local SQLite file is usually faster.
The HTTP API
Each call is a POST with the API key and a JSON body. Every answer is { "ok": true, "result": … } or { "ok": false, "error": "…" }.
| Route | Body | Does |
|---|---|---|
/query |
{ sql, params?, method? } |
Runs one statement. method is all (the default), run, raw or first |
/batch |
{ statements: [{ sql, params? }] } |
Runs several statements as one transaction |
/exec |
{ sql } |
Runs statements written one per line |
curl "$DCX_DB_URL/query" \
-H "Authorization: Bearer $DCX_DB_KEY" \
-H "Content-Type: application/json" \
-d '{"sql": "SELECT * FROM users WHERE id = ?", "params": [1]}'Transactions
BEGIN isn’t available: every statement commits when it succeeds. A batch is the transaction. If one of its statements fails, none is applied.
To run a migration file, split it into statements and send them as one batch. drizzle-kit marks every boundary with --> statement-breakpoint, so no SQL parsing is needed. exec() reads one statement per line, so a statement written across several lines fails there.
Errors
| Status | Meaning |
|---|---|
| 401 | The key is wrong, expired or revoked |
| 403 | The database is suspended |
| 404 | No database at this address |
| 413 | The request or the result is over 16 MB. Page with LIMIT and OFFSET |
| 503 | The request hit a resource limit, most likely a result too large to return |
A 413 for a result, and a 503, come after the statement ran: a write in it has been written. Check before sending it again.
If the connection fails before an answer arrives, the statement may or may not have run. The Python client sends a read again, up to twice, but never a write, because a write sent twice is applied twice. The Node client retries nothing and throws the error fetch gave.
Limits
| Limit | Value |
|---|---|
| Request or result | 16 MB |
| One SQL statement | 100 KB |
| Bound values in one statement | 100 |
| Exact integers | Up to ±9,007,199,254,740,991 |
The Python client works around the bound-value limit for you, and sends long IN (…) lists as one JSON array.
MCP
Every database has MCP built in, so an agent can create tables, store what it learns and read it back.
Pricing
| What | Price | $1 buys |
|---|---|---|
| Storage | $1 per GB, per month | 1 GB for a month |
| Rows read | $1 per billion | 1 billion rows read |
| Rows written | $1 per million | 1 million rows written |
| HTTP requestsFree through a binding | $1 per million | 1 million requests |
See Pricing and billing for a worked example.