Firebase-style code (Firestore API)
Keep your Firestore code: import from @sovaria/sdk/firestore instead of firebase/firestore and point it at your Sovaria project.
@sovaria/sdk/firestore has the functions of Firebase's modular Firestore API on top of Sovaria documents, so moving an app is an import change. Queries, live listeners, batches and transactions are the real Sovaria ones described in Querying documents, Live listeners and Transactions, batches and field transforms.
import { initializeApp } from 'firebase/app'
import { getFirestore, collection, query, where, orderBy, limit, onSnapshot } from 'firebase/firestore'
const db = getFirestore(initializeApp(firebaseConfig))What is supported
| Area | Functions |
|---|---|
| References | collection, doc (path segments or a full path, nested subcollections, auto ids), documentId() |
| Queries | query, where (==, !=, <, <=, >, >=, in, not-in, array-contains, array-contains-any), orderBy, limit, limitToLast, startAt, startAfter, endAt, endBefore (values or snapshots) |
| Reads | getDoc, getDocs, getCountFromServer, onSnapshot (returns its unsubscribe function; docChanges() on snapshots) |
| Writes | setDoc (with { merge: true }), addDoc, updateDoc (object or field/value pairs, dotted paths), deleteDoc |
| Field values | serverTimestamp, increment, arrayUnion, arrayRemove, deleteField, Timestamp |
| Atomic | writeBatch (set / update / delete / commit), runTransaction (retried on conflict) |
Differences from Firebase
- Times are stored as ISO-8601 strings.
Timestamp,DateandserverTimestamp()all become one, so ordering and range filters work; read them back withnew Date(value)orTimestamp.fromDate(new Date(value)). - Offline persistence works the Firebase way —
initializeFirestore(sov, { localCache: persistentLocalCache() })orenableIndexedDbPersistence(db)— and snapshots reportmetadata.fromCacheandmetadata.hasPendingWrites. Multi-tab coordination isn't there yet: use one tab per app, or each tab keeps its own queue. See Offline-first apps. - Access is decided by your collection rules and row policies, not
firestore.rules.sov import firebase --rules firestore.ruleswrites a report of the equivalent of each rule. See Documents. - One rule covers a subcollection under every document: write the path with
*for the document id, likeusers/*/orders. A*stands for exactly one path segment and the depth must match, sousers/*/orderscoversusers/alice/ordersbut notusers/aliceorusers/alice/orders/o1/items. In a policy, comparectx.resource.pattern(ALLOW IF ctx.resource.pattern == "users/*/orders");ctx.resource.namekeeps the full path. Permission claims work the same way:collection:users/*/orders:read. - Document ids and collection names use letters, digits,
_ . @ -(up to 256). The Firebase import cleans other characters and lists every renamed id.
Moving the data too: Migrate from Supabase or Firebase imports Firebase Auth users with their passwords, every collection and subcollection at the same paths, and Storage files.
Something unclear or missing on this page?Tell us