firestore_db_impl
firestore_db_impl
is a Flutter package that provides an implementation layer over Firebase Cloud Firestore for easier and more consistent CRUD operations, querying, and error handling. It aims to reduce boilerplate and standardize interactions with Firestore, allowing developers to focus more on business logic.
Features
- Simplified Firestore CRUD operations
- Stream and Future-based data retrieval
- Structured exception handling
- Query parameter abstraction with enums
- Firestore timestamp and counter utilities
- Extensible and modular architecture
Getting Started
Installation
Add the following to your pubspec.yaml
:
dependencies:
firestore_db_impl: <latest_version>
Import
import 'package:firestore_db_impl/firestore_db_impl.dart';
Usage
Save a Document
final service = FireStoreDbCrudServiceImpl();
String? docId = await service.saveDocument(
data: {'name': 'John Doe'},
collectionPath: 'users',
);
Update a Document
await service.updateDocument(
collectionPath: 'users',
id: docId,
data: {'name': 'Jane Doe'},
);
Query Documents
final queryParams = [
QueryParameter(type: QueryType.where, field: 'role', value: 'admin'),
];
List<Map<String, dynamic>?>? results = await service.getAllDocuments(
collectionPath: 'users',
queryParameters: queryParams,
);
Stream Documents
Stream<List<Map<String, dynamic>?>?> userStream = service.getStreamAllDocuments(
collectionPath: 'users',
);
Get a Document by ID
Map<String, dynamic>? user = await service.getDocumentById(
collectionPath: 'users',
id: docId,
);
Extensions
QueryExtension
: ApplyQueryParameter
to Firestore queriesDocumentSnapshotExtension
: Convert Firestore snapshots to maps or modelsQuerySnapshotExtension
: Convert query results to a list or map
Error Handling
This package provides a robust error-handling system through custom exceptions:
NoInternetConnectionException
UnauthorizedException
BadResponseFormatException
FireStoreException
, and more
Utility Services
FireStoreIteratorServiceImpl
: Increment/Decrement field valuesFireStoreTimerServiceImpl
: Server timestamp handling
Dependencies
cloud_firestore
flutter
License
MIT License
Libraries
- config/dependency_injection/register_fire_store_data_source_service_get_it_di
- data/data_sources/fire_store_collection_ref_service_impl
- data/data_sources/fire_store_db_crud_service_impl
- data/data_sources/fire_store_iterator_service_impl
- data/data_sources/fire_store_timer_service_impl
- data/data_sources/firestore_db_service_impl
- data/data_sources/i_data_sources/i_fire_store_collection_ref_service
- data/data_sources/i_data_sources/i_fire_store_db_crud_service
- data/data_sources/i_data_sources/i_fire_store_Iterator_service
- data/data_sources/i_data_sources/i_fire_store_iterator_service
- data/data_sources/i_data_sources/i_fire_store_timer_service
- data/data_sources/i_data_sources/i_firestor_bd_service
- data/enums/query_type
- data/modlels/query_parameter
- extensions/document_entry_list_extension
- extensions/document_snapshot_extension
- extensions/fire_store_document_snapshot_extension
- extensions/qery_snapshot_extension
- extensions/query_extension
- firestore_db_impl
- utils/exceptions/exception_handler/fire_store_exception_handler
- utils/exceptions/fire_store_exceptions