Loading SQL to Firestore Converter...
Please wait a moment

SQL to Firestore Converter Online — Convert SQL to Google Cloud Firestore SDK Code

Paste your SQL query above and get the equivalent Google Cloud Firestore JavaScript SDK code instantly. Converts WHERE to where() constraints, ORDER BY to orderBy(), INSERT to addDoc() — all in your browser.

How to Convert SQL to Firestore — Step-by-Step

Step 1

Input Your SQL Query

Moving to Firebase and need to translate your SQL queries? Three ways to get started:

Paste directly: Copy your SQL query and paste it into the input editor — conversion happens instantly
Upload a file: Click "Upload" to select a .sql or .txt file from your computer
Load a sample: Click "Sample" to see a SELECT with WHERE, ORDER BY, and LIMIT converted

Example: SQL SELECT with WHERE and ORDER BY

A typical SQL query filtering products by category:

SELECT name, price, rating
FROM products
WHERE category = 'electronics'
  AND price > 50
ORDER BY price ASC
LIMIT 10;
Step 2

Automatic Conversion to Firestore SDK

The converter runs the moment you paste — no button press needed. It generates Firestore v9 modular SDK code with proper imports:

SELECT queries: Become getDocs(query(collection(...), where(...), orderBy(...), limit(...))) calls
Tree-shakeable imports: Only the functions you need are imported — collection, query, where, orderBy, limit, getDocs
Proper operator mapping: SQL operators are mapped to Firestore query constraints like ==, >, <, >=, <=, !=

Example: Firestore v9 SDK Output

The same query, now as Firestore v9 modular SDK code:

import { collection, query, where,
  orderBy, limit, getDocs }
  from "firebase/firestore";

const q = query(
  collection(db, "products"),
  where("category", "==", "electronics"),
  where("price", ">", 50),
  orderBy("price", "asc"),
  limit(10)
);
const snapshot = await getDocs(q);
Step 3

Advanced Operations — INSERT, UPDATE, DELETE

Beyond SELECT queries, the converter handles all write operations using the Firestore data management API:

INSERT INTO: Becomes addDoc(collection(db, "table"), { ... }) with auto-generated document ID
UPDATE: Becomes updateDoc(doc(db, "table", id), { ... }) with the SET values mapped to fields
DELETE: Becomes deleteDoc(doc(db, "table", id)) with document reference

Example: INSERT to addDoc()

SQL INSERT statement:

INSERT INTO products
  (name, price, category)
VALUES
  ('Wireless Mouse', 29.99, 'electronics');

Becomes this Firestore SDK code:

import { collection, addDoc }
  from "firebase/firestore";

await addDoc(
  collection(db, "products"),
  {
    name: "Wireless Mouse",
    price: 29.99,
    category: "electronics"
  }
);
Step 4

Copy or Download Your Firestore Code

When the conversion looks right, grab it:

Copy to clipboard: One-click copy to paste directly into your React, Next.js, or Node.js project
Download as file: Save the converted code as a .js file for use in your project or version control

Frequently Asked Questions — SQL to Firestore Converter

Does Firestore support JOINs?

No — Cloud Firestore is a document database and does not support SQL-style JOINs. The recommended approach is to denormalize your data by duplicating commonly accessed fields across documents, or to use subcollections to model hierarchical relationships. You can also perform multiple queries and merge results client-side. If your application relies heavily on relational queries with JOINs, consider MongoDB which supports $lookup for join-like operations.

Does it support LIKE queries?

Prefix searches (LIKE 'text%') are converted to Firestore range queries using >= and <= operators. However, Firestore does not natively support full-text search patterns like LIKE '%text%' or LIKE '%text'. When the converter encounters these patterns, it adds a comment suggesting third-party search solutions such as Algolia, Typesense, or Elasticsearch which integrate well with Firebase projects.

Which Firestore SDK version does it generate?

The converter generates Firebase v9+ modular SDK code with tree-shakeable imports like import { collection, query, where } from "firebase/firestore". The v9 modular approach is recommended by Google because it enables your bundler (Webpack, Vite, esbuild) to eliminate unused Firestore functions during the build, resulting in significantly smaller JavaScript bundles compared to the older v8 namespaced SDK.

Can I use this with React or Next.js?

Yes. The generated Firestore v9 modular SDK code works directly in React, Next.js, and any JavaScript or TypeScript project. Initialize your Firebase app with initializeApp(config) and getFirestore(app) to get the db instance, then paste the generated code into your component, custom hook, or API route. The modular imports ensure that only the Firestore functions you actually use are included in your production bundle.

How does it handle NULL values?

SQL IS NULL conditions are converted to Firestore where("field", "==", null) constraints. Similarly, IS NOT NULL becomes where("field", "!=", null). Firestore supports null value comparisons natively, so you can filter documents where a specific field is either present with a null value or missing entirely.

Is my data sent to a server?

No. All conversion happens entirely in your browser using client-side JavaScript. Your SQL queries are never transmitted to any server. This makes it safe to use with queries that contain sensitive table names, field names, or values. You can even use the tool offline once the page has loaded.

Is this converter free?

Completely free, no account needed, no usage limits. Convert as many SQL queries to Firestore SDK code as you want. Also check out our other NoSQL converters: SQL to MongoDB, SQL to DynamoDB, SQL to Elasticsearch, and MongoDB Formatter.