Prisma ORM Evaluation for Storage Classes

Overview

This document evaluates the storage backend options for the adblock-compiler project. Prisma ORM with SQLite is now the default storage backend.

Prisma Supported Databases

Prisma is a next-generation ORM for Node.js and TypeScript that supports the following databases:

Relational Databases (SQL)

DatabaseStatusNotes
PostgreSQLFull SupportPrimary recommendation for production
MySQLFull SupportIncluding MySQL 5.7+
MariaDBFull SupportMySQL-compatible
SQLiteFull SupportGreat for local development/embedded
SQL ServerFull SupportMicrosoft SQL Server 2017+
CockroachDBFull SupportDistributed SQL database

NoSQL Databases

DatabaseStatusNotes
MongoDBFull SupportSpecial connector with some limitations

Cloud Database Integrations

ProviderStatusNotes
SupabaseSupportedPostgreSQL-based
PlanetScaleSupportedMySQL-compatible
TursoSupportedSQLite edge database
Cloudflare D1SupportedSQLite at the edge
NeonSupportedServerless PostgreSQL

Upcoming Features (2025)

  • PostgreSQL extensions support (PGVector, Full-Text Search via ParadeDB)
  • Prisma 7 major release with modernized foundations

Current Implementation Analysis

Current Architecture: Prisma with SQLite

The project uses Prisma ORM with SQLite as the default storage backend:

PrismaStorageAdapter (SQLite/PostgreSQL/MySQL)
├── CachingDownloader
│   ├── ChangeDetector
│   └── SourceHealthMonitor
└── IncrementalCompiler (MemoryCacheStorage)

Key Characteristics:

  • Flexible database support (SQLite default, PostgreSQL, MySQL, etc.)
  • Cross-runtime compatibility (Node.js, Deno, Bun)
  • Hierarchical keys: ['cache', 'filters', source]
  • Application-level TTL support
  • Type-safe generic operations

Storage Classes Summary

ClassPurposeComplexity
PrismaStorageAdapterCore KV operationsLow
D1StorageAdapterCloudflare edge storageLow
CachingDownloaderSmart download cachingMedium
ChangeDetectorTrack filter changesLow
SourceHealthMonitorTrack source reliabilityLow
IncrementalCompilerCompilation cachingMedium

Comparison: Prisma SQLite vs Other Options

Feature Comparison

FeaturePrisma/SQLitePrisma/PostgreSQLCloudflare D1
Schema DefinitionPrisma SchemaPrisma SchemaSQL
Type SafetyGenerated typesGenerated typesManual
QueriesRich query APIRich query APIRaw SQL
RelationsFirst-classFirst-classManual
MigrationsBuilt-inBuilt-inManual
TTL SupportApplication-levelApplication-levelApplication-level
TransactionsFull ACIDFull ACIDLimited
ToolingPrisma StudioPrisma StudioWrangler CLI
RuntimeAllAllWorkers only
InfrastructureNone (embedded)Server requiredEdge

Pros and Cons

Prisma with SQLite (Default)

Pros:

  • Zero infrastructure overhead
  • Cross-runtime compatibility (Node.js, Deno, Bun)
  • Simple API for KV operations
  • Works offline/locally
  • Type-safe with generated client
  • Built-in migrations and schema management
  • Excellent tooling (Prisma Studio, CLI)
  • Fast for simple operations

Cons:

  • Single-instance only (no shared database)
  • TTL must be implemented in application code
  • Not suitable for multi-server deployments

Prisma with PostgreSQL

Pros:

  • Multi-instance support
  • Full ACID transactions
  • Rich query capabilities
  • Production-ready for scaled deployments
  • Same API as SQLite

Cons:

  • Requires database server
  • Additional infrastructure overhead
  • More complex setup

Cloudflare D1

Pros:

  • Edge-first architecture
  • Low latency globally
  • Serverless pricing model
  • No infrastructure management

Cons:

  • Cloudflare Workers only
  • Limited query capabilities
  • Different API from Prisma adapters

Use Case Analysis

Current Use Cases

Use CaseData PatternComplexitySQLite FitPostgreSQL FitD1 Fit
Filter list cachingSimple KV with TTLLowExcellentExcellentGood
Health monitoringAppend-only metricsLowGoodBetterGood
Change detectionSnapshot comparisonLowGoodGoodGood
Compilation historyTime-series queriesMediumGoodBetterGood

When to Use PostgreSQL

PostgreSQL is beneficial if:

  1. Multi-instance deployment - Shared database across servers/workers
  2. Complex queries required - Filtering, aggregation, joins
  3. Data relationships - Related entities need referential integrity
  4. Audit/compliance needs - Full transaction logs, ACID guarantees
  5. High concurrency - Multiple writers accessing the same data

When to Use SQLite (Default)

SQLite remains the best choice when:

  1. Single-instance deployment - One server or local development
  2. Simplicity is paramount - No external infrastructure needed
  3. Local/offline use - Application runs standalone
  4. Minimal maintenance - No database server to manage

When to Use Cloudflare D1

D1 is the best choice when:

  1. Edge deployment - Running on Cloudflare Workers
  2. Global distribution - Need low latency worldwide
  3. Serverless - No infrastructure management desired

Recommendation

Summary

Prisma with SQLite is the default choice for simplicity and zero infrastructure.

The existing storage patterns (caching, health monitoring, change detection) are well-suited to the Prisma adapter pattern. SQLite provides a simple embedded database that requires no external infrastructure.

Architecture

The project uses a flexible adapter pattern:

classDiagram
    class IStorageAdapter {
        +set~T~(key: string[], value: T, ttl?: number) Promise~boolean~
        +get~T~(key: string[]) Promise~StorageEntry~T~ | null~
        +delete(key: string[]) Promise~boolean~
        +list~T~(options) Promise~Array~{ key: string[]; value: StorageEntry~T~ }~~
    }
    IStorageAdapter <|-- PrismaStorageAdapter
    IStorageAdapter <|-- D1StorageAdapter

This allows switching storage backends based on deployment environment without changing application code.

Implementation Status

The project includes:

  1. IStorageAdapter - Abstract interface for storage backends
  2. PrismaStorageAdapter - Default implementation (SQLite/PostgreSQL/MySQL)
  3. D1StorageAdapter - Cloudflare edge deployment
  4. prisma/schema.prisma - Prisma schema (for SQLite/PostgreSQL/MongoDB)

Conclusion

AspectRecommendation
Default UsagePrisma with SQLite
Multi-instancePrisma with PostgreSQL
Edge DeploymentCloudflare D1
MongoDBPrisma with MongoDB connector

The storage abstraction layer enables switching backends based on deployment requirements without affecting the application code.

References