Does Firebase Work With Drizzle ORM?

Partially CompatibleLast verified: 2026-02-26

You can use Drizzle ORM with Firebase, but only with Firestore or Cloud SQL—not Realtime Database—and it requires careful architectural decisions.

Quick Facts

Compatibility
partial
Setup Difficulty
Moderate
Official Integration
No — community maintained
Confidence
high
Minimum Versions
Firebase: 9.0.0
Drizzle ORM: 0.28.0

How Firebase Works With Drizzle ORM

Firebase and Drizzle ORM can work together, but with important limitations. Drizzle is a SQL-first ORM designed for traditional SQL databases, while Firebase's primary offering—Realtime Database—is NoSQL and document-based. However, if you use Firebase's Cloud SQL connector or Firestore with a separate Cloud SQL instance, Drizzle becomes viable. The typical architecture involves using Firebase Authentication and other Firebase services (hosting, storage) alongside a Cloud SQL database managed by Drizzle ORM. You'd handle auth through Firebase Admin SDK and queries through Drizzle. The developer experience is smooth for the SQL layer, but you're essentially using Firebase as a backend service suite rather than a unified database solution. This works well for teams wanting Firebase's infrastructure but needing relational data—common in e-commerce and SaaS apps.

Best Use Cases

E-commerce platforms using Firebase Auth + Drizzle for product/order management in Cloud SQL
SaaS applications combining Firebase Auth, Firestore for real-time features, and Cloud SQL for transactional data
Multi-tenant apps using Firebase for user management while Drizzle handles schema-driven relational data
Real-time collaborative tools where Firebase handles presence/notifications and Drizzle manages persistent structured data

Firebase Cloud Function with Drizzle ORM

bash
npm install firebase-admin drizzle-orm @google-cloud/sql-connector pg
typescript
import * as functions from 'firebase-functions';
import { drizzle } from 'drizzle-orm/node-postgres';
import { users } from './schema';
import { Connector } from '@google-cloud/sql-connector';
import postgres from 'pg';

const connector = new Connector();

const pool = new postgres.Pool({
  user: 'postgres',
  password: process.env.DB_PASSWORD,
  database: 'myapp',
  max: 5,
});

const db = drizzle(pool);

export const createUser = functions.https.onCall(async (data, context) => {
  if (!context.auth) throw new functions.https.HttpsError('unauthenticated', 'Auth required');
  
  const result = await db.insert(users).values({
    email: data.email,
    firebaseUid: context.auth.uid,
  }).returning();
  
  return result[0];
});

Known Issues & Gotchas

critical

Firebase Realtime Database has no SQL interface—Drizzle cannot query it directly

Fix: Use Cloud SQL instead, or accept that Realtime Database queries must bypass Drizzle entirely

warning

Connection pooling and Firebase Cloud Functions have timeout constraints that can interrupt long Drizzle queries

Fix: Keep queries optimized, use serverless-compatible connection pools (PgBouncer), or implement query timeouts

warning

Firebase Auth tokens and Drizzle database credentials are separate concerns requiring dual authentication logic

Fix: Use Firebase Admin SDK in backend functions to validate tokens before executing Drizzle queries; never expose DB credentials to client

info

Mixing Firestore and Cloud SQL can create eventual consistency issues and data synchronization challenges

Fix: Clearly separate concerns—use Firestore for real-time data, Cloud SQL+Drizzle for transactional/relational data

Alternatives

  • Supabase + Drizzle ORM: PostgreSQL-first with built-in Auth and Drizzle support
  • Firebase Firestore + Prisma: NoSQL-native with better Firebase integration
  • PlanetScale + Drizzle: MySQL serverless optimized for Drizzle, pair with Firebase Auth separately

Resources

Related Compatibility Guides

Explore more compatibility guides