dorm_firebase_database
A dORM's database engine implementation using the
firebase_database
package.
Getting started
Run the following commands in your command prompt:
dart pub add dorm_firebase_database
Using dorm_annotations
and
dorm_generator
, generate your dORM code:
dart run build_runner build
This will create a Dorm
class, which you can use to connect to this package.
Usage
Before accessing any Firebase classes, initialize your app:
void main() async {
await Firebase.initializeApp();
// Alternatively, if you're working with non-default apps
await Firebase.initializeApp(name: 'app-1');
// You can also pass the `options` parameter with the options generated by FlutterFire
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}
Create a FirebaseInstance
, a class that manages your current Firebase app:
void main() {
const FirebaseInstance instance = FirebaseInstance();
// Alternatively, if you're working with non-default apps
final FirebaseInstance instance = FirebaseInstance.custom(Firebase.app('app-1'));
// You can also to control the offline management, through `offlineMode`
const FirebaseInstance instance = FirebaseInstance(offlineMode: OfflineMode.include);
}
With this instance, create a Reference
:
void main() {
final Reference reference = Reference(instance);
// Alternatively, if you want to create your database under 'production/'
final Reference reference = Reference(instance, 'production');
}
Finally, pass the reference created above to your generated Dorm
class:
void main() {
final Dorm dorm = Dorm(reference);
}