Firebase Database Modeler is a TypeScript-first library designed to enhance development with the Firebase Realtime Database by providing a structured, strongly-typed modeling layer. Currently at version 2.8.0, it aims to abstract the complexities of database path management and data serialization through a declarative model definition. It offers robust IntelliSense support, automatically converting between the defined model schema and the actual database structure. The library supports integration with `firebase`, `firebase-admin`, and `react-native-firebase`, making it versatile for various JavaScript environments. While a strict release cadence isn't published, the developer indicates active use in a real project, implying ongoing maintenance and feature evolution. Its key differentiation lies in bringing advanced type safety and a clear object-oriented approach to Firebase Realtime Database interactions, simplifying complex data structures and reducing common runtime errors associated with schema mismatches.
npm install firebase-database-modelerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates defining a typed model for a Firebase Realtime Database 'stores' collection, initializing Firebase, setting the default database for the modeler, and performing type-safe create, update, and fetch operations using the defined model with dynamic path segments.
Ensure `modelerSetDefaultDatabase(firebase.database());` is called once during application initialization, or pass the database instance directly to `_root({...}, database)` or `node._ref(database)` calls.To perform a partial update, target the specific child node you wish to modify (e.g., `stores.$storeId.name._set(newName, storeId)` instead of `stores.$storeId._set(...)`). If a property can be optional, define it with `_<Type | null>('dbKey')` in your model.Be explicit in your model definitions and ensure consistency. Remember that the model property name (`name`) is for TypeScript and IntelliSense, while the string in `_('n')` is the actual key used in Firebase Realtime Database paths.Always provide the concrete value for dynamic path segments as the final argument to any database operation method on a variable node. The type system will typically guide you, but be mindful during refactoring.
Ensure you have correctly imported the Realtime Database service. For Firebase v8 or compat mode: `import firebase from 'firebase/compat/app'; import 'firebase/compat/database';`. For modular v9+: `import { getDatabase } from 'firebase/database';` and initialize the database instance from `getDatabase(app)`.Either provide all required properties for the `_set()` call or, if you intend to perform a partial update, target a more specific child node in your model (e.g., `stores.$storeId.name._set(newName, storeId)`). Alternatively, adjust your model definition to mark properties as optional (`_<Type | null>('dbKey')`) if they are not always present.Verify that `modelerSetDefaultDatabase(firebase.database());` has been executed before any model operations, or that the `database` argument was correctly passed to your `_root()` model definition.