rz-firestore
RZ Firestore
A facade service to simply communicate with Google Cloud Firestore DB
Before you use
npm install firebase
npm install @angular/fire
In your module's imports array add: AngularFireModule.initializeApp(environment.firebaseConfig)
Methods
readStream<T>(collection: string, query?: RZFirestoreQuery, config?: RZFirestoreConfig): Observable<T[]>
Gets documents array on every DB change
read<T>(collection: string, query?: RZFirestoreQuery, config?: RZFirestoreConfig): Promise<T[]>
Gets documents array
readByDocumentId<T>(collection: string, id: string, config?: RZFirestoreConfig): Promise<T>
Gets document by ID
create(collection: string, document: object): Promise<string>
Creates a new document and returns the its ID
update(collection: string, id: string, document: object): Promise<void>
Creates a new document or replaces entire existing document
patch(collection: string, id: string, propertiesToChange: object): Promise<void>
Creates or changes properties of existing document (not deletes)
delete(collection: string, id: string): Promise<void>
Deletes an existing document
toReference(collection: string, id: string): DocumentReference
Gets a document reference
RZFirestoreQuery Object
RZFirestoreQuery {
where?: RZFirestoreFilter[]; <-- Logical AND relation
orderBy?: RZFirestoreSort[]; <-- Logical AND relation
limit?: number;
}
RZFirestoreFilter {
field: string;
operator: RZFirestoreFilterOperator;
value: unknown;
}
RZFirestoreSort {
field: string;
direction?: RZFirestoreSortDirection;
}
enum RZFirestoreFilterOperator {
Equal = '==',
NotEqual = '!=',
LessThan = '<',
LessThanEqual = '<=',
GreaterThan = '>',
GreaterThanEqual = '>=',
In = 'in',
NotIn = 'not-in',
ArrayContains = 'array-contains',
ArrayContainsAny = 'array-contains-any'
}
enum RZFirestoreSortDirection {
Asc = 'asc',
Desc = 'desc'
}
RZFirestoreConfig Object
includeDocumentId: boolean (default true)
(id fields are included automatically in documents, change this parameter to false to prevent it)
refConversionDepth: number (default 10)
(references are converted automatically to documents, this parameter declares how deep to go with the conversion. 0 for no conversion at all)