DORM makes building multi-tenant applications on Cloudflare ridiculously easy by letting you:
- Create unlimited SQLite DBs on the fly (up to 10GB each)
- Query them directly from anywhere in your worker (not just inside DOs)
- Explore and manage your data with built-in Outerbase integration
- Migrate once, everywhere with built-in JIT migration-support
Perfect for SaaS applications, user profiles, rate limiting, or any case where you need isolated data stores that are lightning fast at the edge.
Demo app: https://dorm.wilmake.com | Give me a like/share on X
Feature | Vanilla DOs | DORM ποΈ | D1 | Turso |
---|---|---|---|---|
Multi-tenant | β Unlimited | β Unlimited | β One DB | Pricey |
Run code where your DB is (Never >1 round-trip) |
β | β | β | β |
Query from worker | β Only in DO | β | β | β |
Data Explorer | β | β Outerbase | β | β |
Migrations | β | β | β | β |
Edge Performance | Closest to user | Closest to user | Global edge | Global edge |
Developer Experience | β Verbose, complex | β Clean, low verbosity | β Good | Good, not CF native |
See Turso vs DORM and DORM vs D1 for a more in-depth comparison with these alternatives. Also, see the pricing comparison here
Check out the live demo showing multi-tenant capabilities.
npm i dormroom@next
DORM is built atop of modular primitives called 'Power Objects'. Check https://itscooldo.com for more information!
Summary | Prompt it |
---|---|
Working example/template on how to use this | |
Entire implementation of the package | |
Create a customized guide for a particular usecase | |
General information |
Local Development:
- Install: https://github.com/outerbase/studio
- Create starbase connecting to: http://localhost:8787/{tenant}/api/db (or your port, your prefix)
Production: Use https://studio.outerbase.com
Create a separate database for each customer/organization:
const client = createClient({
doNamespace: env.DORM_NAMESPACE,
ctx: ctx,
configs: [
{ name: `tenant:${tenantId}` }, // One DB per tenant
{ name: "aggregate" }, // Optional: Mirror to aggregate DB
],
});
Store user data closest to where they access it:
const client = createClient({
doNamespace: env.DORM_NAMESPACE,
ctx: ctx,
configs: [
{ name: `user:${userId}` }, // One DB per user
],
});
Mirror tenant operations to a central database for analytics:
const client = createClient({
doNamespace: env.DORM_NAMESPACE,
ctx: ctx,
configs: [
{ name: `tenant:${tenantId}` }, // Main DB
{ name: "aggregate" }, // Mirror operations to aggregate DB
],
});
When creating mirrors, be wary of naming collisions and database size:
-
Auto increment drift: when you use auto-increment and unique IDs (or columns in general), you may run into the issue that the value will be different in the aggregate DB. This causes things to drift apart! To prevent this issue I recommend not using auto increment or random in the query, and generate unique IDs beforehand when doing a query, so the data remains the same.
-
Size: You have max 10GB. When you chose to use an aggregate DB of some sort, ensure to keep this in mind.
- Direct SQL anywhere: No need to write DO handler code - query from your worker
- Outerbase integration: Explore and manage your data with built-in tools
- JSON Schema support: Define tables using JSON Schema with automatic SQL translation
- Streaming queries: Efficient cursor implementation for large result sets
- JIT Migrations: Migrations are applied when needed, just once, right before a DO gets accessed (via
@Migratable
) - Data mirroring: Mirror operations to aggregate databases for analytics
- Low verbosity: Clean API that hides Durable Object complexity
import { Migratable } from "migratable-object";
import { Streamable } from "remote-sql-cursor";
@Migratable({
migrations: {
1: [`CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY, name TEXT)`],
2: [`ALTER TABLE users ADD COLUMN email TEXT`],
},
})
@Streamable()
export class DORM extends DurableObject {
sql: SqlStorage;
constructor(state: DurableObjectState, env: any) {
super(state, env);
this.sql = state.storage.sql;
}
getDatabaseSize() {
return this.sql.databaseSize;
}
}
import { jsonSchemaToSql, TableSchema } from "dormroom";
const userSchema: TableSchema = {
$id: "users",
properties: {
id: { type: "string", "x-dorm-primary-key": true },
name: { type: "string", maxLength: 100 },
email: { type: "string", "x-dorm-unique": true },
},
required: ["id", "name"],
};
const sqlStatements = jsonSchemaToSql(userSchema);
// Get a cursor for working with large datasets
const cursor = client.exec<UserRecord>("SELECT * FROM users");
// Stream results without loading everything into memory
for await (const user of cursor) {
// Process each user individually
}
// Or get all results at once
const allUsers = await cursor.toArray();
// Access your database via REST API
const middlewareResponse = await client.middleware(request, {
prefix: "/api/db",
secret: "my-secret-key",
});
if (middlewareResponse) {
return middlewareResponse;
}
You can extend DORM with your own DO implementation to circumvent limitations doing single queries remotely gives you.
@Migratable({
migrations: {
1: [`CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY, name TEXT)`],
},
})
@Streamable()
export class YourDO extends DurableObject {
sql: SqlStorage;
constructor(state: DurableObjectState, env: any) {
super(state, env);
this.sql = state.storage.sql;
}
async myExtendedFunction() {
// Multiple queries in one transaction
const users = await this.sql.exec("SELECT * FROM users").toArray();
const count = await this.sql
.exec("SELECT COUNT(*) as count FROM users")
.one();
return { users, count };
}
getDatabaseSize() {
return this.sql.databaseSize;
}
}
This allows:
- Doing a multitude of SQL queries inside of your DO from a single API call
- Using alarms and other features
- Complex transactions
- β Nearly zero overhead: Thin abstraction over DO's SQLite
- β Edge-localized: Data stored closest to where it's accessed
- β Up to 10GB per DB: Sufficient for most application needs
- β Localhost isn't easily accessible YET in https://studio.outerbase.com so you need to deploy first, use a tunnel, or run the outerbase client on localhost.
- X-OAuth Template using DORM
- Follow me on X for updates
- Original project: ORM-DO
- Inspiration/used work - The convention outerbase uses is reapplied to make the integration with outerbase work!
- Original idea for mirroring
- DORM uses a 'remote sql cursor' at its core - see repo+post here
- v1.0.0@next-25 - Breaking change - July 8, 2025
DORM is currently in beta. API may change!