Skip to content
This repository has been archived by the owner on Jun 25, 2023. It is now read-only.

An enhanced version of cloud firestore dart package with support for filtering sorting, limiting, error handling, and success scenarios

License

Notifications You must be signed in to change notification settings

sliit-foss/enhanced_cloud_firestore

Repository files navigation

enhanced_cloud_firestore

IMPORTANT !!!

This project has been migrated to the following monorepo and will no longer be maintained here.

An enhanced version of the cloud firestore dart package with support for filtering, sorting, limiting, error handling and success scenarios

Getting started

  • Add Firebase Core as a dependency in your pubspec.yaml file
  • In your main.dart file, initialize a firebase app

Usage

Read data in a collection

final res = EnhancedFirestore.read(collection: 'users');

Write data to a collection

final res = EnhancedFirestore.write(
    collection: 'users',
    payload: {
     'name': 'John',
     'email': 'john@gmail.com',
     'age': '45',
    },
)

Update data in a collection

final res = EnhancedFirestore.update(
    collection: 'users',
    payload: {
     'name': 'John Cena',
     'email': 'johncena@gmail.com',
     'age': '46',
    },
    filters: [
        {
            'field': 'email',
            'filter': FirestoreFilter.isEqualTo,
            'value': 'john@gmail.com',
        }
    ]
)

Delete data in a collection

final res = EnhancedFirestore.delete(
    collection: 'users',
    filters: [
        {
            'field': 'email',
            'filter': FirestoreFilter.isEqualTo,
            'value': 'johncena@gmail.com',
        }
    ]
)

Additional Parameters

All of the above four methods are able to take in the following parameters optionally:


  • filters - An array of filters to apply on the collection. Specified as a json object list with the following keys ->
    • field - The document field to apply the filter on
    • filter - The filter type to apply (is an enum of type FirestoreFilter)
    • value - The field content to match against

  • onSuccess - A function which will execute on success scenarios

  • onError - A function which will execute on error scenarios

The read function can take in the following attributes other than those specified above


  • sorts - An array of sorts to apply on the collection. Specified as a json object list with the following keys ->
    • field - The document field to apply the sort on
    • descending - A boolean value denoting the sort direction (specify as false to sort in ascending order )

  • limit - A limit on the number of returned records

Caution

  • An empty list of filters on an update function will result in the entire collection being updated

  • An empty list of filters on a delete function will result in the entire collection being deleted


Credits

Based on the original cloud_firestore package by Google (https://pub.dev/packages/cloud_firestore)

About

An enhanced version of cloud firestore dart package with support for filtering sorting, limiting, error handling, and success scenarios

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages