data_layer_firestore 0.0.3
data_layer_firestore: ^0.0.3 copied to clipboard
Provides Firestore-specific bindings for pkg:data_layer.
Data Layer Firestore #
An add-on to pkg:data_layer which provides a Firestore implementation of the Source interface.
Motivation #
Seamlessly plug Cloud Firestore into your Flutter apps' data_layer repositories with the FirestoreSource class from this package.
Index #
- Motivation
- Architecture
- Getting Started
- Creating a FirestoreSource
- Server Timestamp Fields
- Untyped Merges (
raw)
Architecture #
pkg:data_layer_firestore provides a FirestoreSource class which implements the WatchableSource interface to seamlessly integrate Cloud Firestore into your data_layer ecosystem. This source handles all necessary translation between data_layer's request details and Firestore's querying syntax, while also supporting real-time data streaming.
Getting started #
Add the following to your pubspec.yaml:
dependencies:
data_layer: ^0.0.7
data_layer_firestore: ^0.0.2
Creating a FirestoreSource #
Instances of a FirestoreSource are meant to be used within the context of a SourceList.
SourceList(
...
sources: [
LocalMemorySource(bindings: User.bindings),
FirestoreSource(
FirebaseFirestore.instance,
bindings: User.bindings,
collectionName: 'users',
),
],
)
Server Timestamp Fields #
FirestoreSource can automatically populate server timestamps on document creation and update operations:
FirestoreSource(
FirebaseFirestore.instance,
bindings: User.bindings,
collectionName: 'users',
onCreateServerTimestampFields: ['createdAt'],
onUpdateServerTimestampFields: ['updatedAt'],
)
Untyped Merges (raw) #
To merge an arbitrary Map<String, dynamic> into a document without deserializing into a full object model:
await firestoreSource.raw('user_123', {
'lastActive': DateTime.now(),
'status': 'online',
});