πŸ—„οΈ Cloudflare D1 Database

Serverless SQLite at the edge with zero cold starts

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', '[email protected]', '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

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

Future Enhancements

Start Building with D1

Experience serverless SQL at the edge with ProposalForge

Try ProposalForge