Edge-Native SQL Database
Cloudflare D1 is the first queryable serverless database built on SQLite, running on Cloudflare's edge network. ProposalForge uses D1 to store proposals, track PDF generation history, and manage application stateβall with sub-millisecond latency.
What Makes D1 Special?
β‘ SQLite at the Edge
Built on SQLite, the world's most deployed database. Runs directly on Workers with zero cold starts.
π Global Replication
Automatic replication across Cloudflare's network. Read from the nearest edge location worldwide.
π Standard SQL
Full SQL support with transactions, indexes, and joins. Use familiar SQL syntax without limitations.
π° Generous Free Tier
100,000 reads and 50,000 writes per day on the free tierβplenty for most applications.
π Type Safe
Use typed queries with Drizzle ORM or raw SQL. Get autocomplete and compile-time validation.
π Instant Queries
Sub-millisecond query execution. Database runs in the same V8 isolate as your Worker code.
ProposalForge Database Schema
ProposalForge uses a simple, efficient schema optimized for proposal management and PDF tracking:
CREATE TABLE proposals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
client_name TEXT NOT NULL,
client_email TEXT,
consultant_name TEXT NOT NULL,
consultant_email TEXT,
project_description TEXT,
total_amount REAL NOT NULL,
currency TEXT DEFAULT 'USD',
tax_rate REAL DEFAULT 0,
discount_amount REAL DEFAULT 0,
payment_terms TEXT,
delivery_terms TEXT,
warranty_terms TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE pdf_generations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
proposal_id INTEGER,
filename TEXT NOT NULL,
file_size INTEGER,
cloud_url TEXT,
generated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (proposal_id) REFERENCES proposals(id)
);
CREATE INDEX idx_proposals_created ON proposals(created_at);
CREATE INDEX idx_pdf_generations_proposal ON pdf_generations(proposal_id);
CREATE INDEX idx_pdf_generations_date ON pdf_generations(generated_at);
How ProposalForge Uses D1
π Proposal Storage
Every proposal is saved to D1 with full client details, pricing, and terms for future retrieval.
π PDF Tracking
Track every PDF generated, including filename, file size, cloud URL, and generation timestamp.
π Search & Filter
Query proposals by client name, date range, amount, or currency using efficient SQL indexes.
π Analytics
Generate reports on proposal volume, average deal size, conversion rates, and PDF downloads.
Example Database Operations
Insert a New Proposal:
const result = await env.DB.prepare(`
INSERT INTO proposals (
title, client_name, client_email,
consultant_name, total_amount, currency
) VALUES (?, ?, ?, ?, ?, ?)
`).bind(
'Website Redesign Project',
'Acme Corp',
'contact@acme.com',
'John Consultant',
15000.00,
'USD'
).run();
const proposalId = result.meta.last_row_id;
Log PDF Generation:
await env.DB.prepare(`
INSERT INTO pdf_generations (
proposal_id, filename, file_size, cloud_url
) VALUES (?, ?, ?, ?)
`).bind(
proposalId,
'proposal-acme-corp-2026-01.pdf',
248576,
'https://cdn.example.com/proposals/2026/01/acme.pdf'
).run();
Query Recent Proposals:
const proposals = await env.DB.prepare(`
SELECT * FROM proposals
WHERE created_at >= datetime('now', '-30 days')
ORDER BY created_at DESC
LIMIT 50
`).all();
return Response.json(proposals.results);
Performance Characteristics
- β‘ Query Latency: < 1ms for simple queries
- π Throughput: 10,000+ queries per second per database
- πΎ Database Size: Up to 10GB on paid plans
- π Replication: Automatic multi-region replication
- π Indexes: B-tree indexes for fast lookups
- π Transactions: Full ACID compliance with SQLite transactions
D1 vs Traditional Databases
π« No Connection Pools
Database runs in-process with your Worker. No TCP connections, no connection limits.
π« No Cold Starts
Unlike Aurora Serverless, D1 is always hot. Queries execute instantly, even after idle periods.
π« No VPC Configuration
No networking setup required. D1 bindings are automatically available in your Worker code.
π« No Scaling Concerns
Automatically scales with your Worker traffic. No capacity planning or instance sizing.
Database Management
Wrangler CLI Integration:
# Create a new D1 database
wrangler d1 create proposal-db
# Execute SQL migrations
wrangler d1 execute proposal-db --file=schema.sql
# Query database locally
wrangler d1 execute proposal-db --command="SELECT * FROM proposals"
# Backup database
wrangler d1 backup create proposal-db
Data Migration & Seeding
ProposalForge includes migration scripts for easy database setup:
-- migrations/001_initial_schema.sql
CREATE TABLE IF NOT EXISTS proposals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- migrations/002_add_pdf_tracking.sql
CREATE TABLE IF NOT EXISTS pdf_generations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
proposal_id INTEGER,
filename TEXT NOT NULL,
generated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
Cost Structure Free Tier
- π Free: 100,000 reads per day
- π Free: 50,000 writes per day
- π Free: 5GB storage included
- π Paid: $0.000001 per read ($1 per million)
- π Paid: $0.000001 per write ($1 per million)
- π Paid: $0.75/GB/month for storage beyond 5GB
Future Enhancements
- π Read Replicas: Dedicated read replicas for analytics queries
- π Time Travel Queries: Query historical data with point-in-time recovery
- π Full-Text Search: Built-in FTS5 for searching proposal content
- π Analytics Engine: Integration with Cloudflare Analytics Engine for metrics
- π Row-Level Security: Fine-grained access control with SQL policies