A simple, lightweight NoSQL database written in pure Dart, with support for concurrency control, indexing, pagination, transactions, and TTL.
synchronized library for thread-safe access to data, with locks.limit and offset to improve performance.Add the simple_storage dependency:
flutter pub add simple_storage
Import:
import 'package:simple_storage/simple_storage.dart';
Create a Database Instance:
final db = Database('./my_database'); // Specify the storage path
Create or Access a Collection:
final users = await db.collection('users', indexes: ['age', 'name']);
indexes parameter is a List<String> of properties that should be indexed. Indexing can speed up lookups based on these properties but can also slow down insertions if used too much.put method to store data using a key and a value.ttl parameter specifies a time-to-live for the data. After that time, the data will be removed when loading from disk, or when accessing using get or getAll.get method to retrieve data using a key.key parameter as a field that has been indexed you should also provide the value to filter the results.getAll with limit and offset to get data in pages.limit specifies the maximum amount of data returned, and the offset specifies which entry is the start of the page.Handle Errors:
The application throws specific errors:
DatabaseCreateException: when the database fails to create the storage directory.CollectionLoadException: when a collection fails to load from the disk.CollectionSaveException: when a collection fails to save to disk.CollectionNotFoundException: when a collection is not found.These exceptions should be caught by the application to handle specific error cases.
Database:
collection method returns a collection for a specific name.Collection:
ttl.put, get, getAll, and delete data.startTransaction method.Transaction:
put, delete, commit and rollback to manage the transaction.The database uses custom exception classes for clear and detailed error reporting:
DatabaseCreateExceptionCollectionLoadExceptionCollectionSaveExceptionCollectionNotFoundExceptionThese exceptions provide specific error messages, which you can use to provide feedback to your user, and to help debug.
Contributions are welcome! If you have ideas for enhancements or find any bugs, please feel free to:
This project is licensed under the MIT License - see the LICENSE file for details.