DatabaseService<T> class
The base database service class that you can instiantiate or extend
DatabaseService<Note> noteDBs = DatabaseService<Note>("notes",fromDS: (id,data) => Note.fromDS(id,data), toMap: (note)=>note.toMap());
noteDBs.getQueryList()
.then((List<Note> notes)=>print(notes));
Constructors
-
DatabaseService(String collection, {required T fromDS(String, Map<
String, dynamic> ?), Map<String, dynamic> toMap(T)?}) -
Create instance of Database service
collection path is required
fromDS is required to get document snapshot as object
T
Properties
- collection ↔ String
-
path of the collection to use as base path for all the operations
getter/setter pair
- db → FirebaseFirestore
-
Returns instance of FirebaseFirestore
no setter
-
fromDS
→ T Function(String, Map<
String, dynamic> ?) -
Function to convert the firestore
DocumentSnapshot
into the model classT
providesid
andMap<String,dynamic> data
and must returnT
object.final - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
toMap
→ (Map<
String, dynamic> Function(T)?) -
Function to convert object
T
to Map<String,dynamic>, receives instance ofT
, and should always return Map<String,dynamic>final
Methods
-
create(
Map< String, dynamic> data, {String? id}) → Future -
Creates new document based on the provided
data
andid
in the collection Ifid
is null,id
will be auto generated by firestore -
getListFromTo(
String field, DateTime from, DateTime to, {List< QueryArgsV2> args = const []}) → Future<List< T> > -
Returns the list of documents from
from
date toto
date matched byfield
is ordered by thefield
provided. additionalargs
can be supplied to perform specific query. -
getQueryList(
{List< OrderBy> ? orderBy, List<QueryArgsV2> ? args, int? limit, dynamic startAfter, dynamic startAt, dynamic endAt, dynamic endBefore}) → Future<List< T> > -
Returns the list of documents from collection, in the order provided in
orderBy
and matches theargs
supplied. usestartAfter
,startAt
,endAt
,endBefore
to perform cursor based queries and pagination of data -
getSingle(
String id) → Future< T?> -
Get a single document of
id
from the collection Returns null if the document does not exist -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeItem(
String id) → Future< void> -
Removes item with
id
from collection -
streamList(
) → Stream< List< T> > - Returns list of all the documents from collection as a stream so that changes can be listened
-
streamListFromTo(
String field, DateTime from, DateTime to, {List< QueryArgsV2> args = const []}) → Stream<List< T> > -
Returns the list of documents from
from
date toto
date matched byfield
from collection as a stream so that changes can be listened and is ordered by thefield
provided. additionalargs
can be supplied to perform specific query. -
streamQueryList(
{List< OrderBy> ? orderBy, List<QueryArgsV2> ? args, int? limit, dynamic startAfter, dynamic startAt, dynamic endBefore, dynamic endAt}) → Stream<List< T> > -
Returns the list of documents from collection, in the order provided in
orderBy
and matches theargs
supplied as a stream so that changes can be listened. UsestartAfter
,startAt
,endAt
,endBefore
to perform cursor based queries and pagination of data -
streamSingle(
String id) → Stream< T?> -
Returns a single document of
id
from collection as stream so that updates can be listened -
toString(
) → String -
A string representation of this object.
inherited
-
updateData(
String id, Map< String, dynamic> data) → Future<void> -
Updates the document with
id
with the provideddata
to the collection
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited