angel3_sembast 10.0.0
angel3_sembast: ^10.0.0 copied to clipboard
A plugin service that persist data to Sembast for Angel3 framework.
Sembast Persistent Service for Angel3 #
A plugin service that persist data to Sembast for Angel3 framework.
Installation #
Add the following to your pubspec.yaml:
dependencies:
angel3_sembast: ^10.0.0
Usage #
This library exposes one main class: SembastService.
SembastService #
This class interacts with a Database and Store (from package:sembast) and serializes data to and from Maps.
Querying #
You can query these services as follows:
/path/to/service?foo=bar
The above will query the database to find records where 'foo' equals 'bar'. A record must match every field of the query, and id matches the key of the record.
Sort with $sort: a field name sorts by it in ascending order, and a map of field names to 1 (ascending) or -1 (descending) sorts by each of them:
/path/to/service?$sort=name
await service.index({r'$sort': {'name': -1}});
Removing all records (with allowRemoveAll, or on the server side) removes only those that match the query, if there is one.
Of course, you can use package:sembast queries. Just pass a Finder as query within params:
var queried = await service.index({
'query': Finder(filter: Filter.equals('foo', 'bar')),
});
See the tests for more usage examples.
Migrating from 9.x to 10.0.0 #
The breaking changes of each release are listed in the CHANGELOG. Those of 10.0.0 that may need changes in an app:
- Queries: a record matches a query only if it matches every field of it, where matching any field was enough.
$sort:-1sorts in descending order and1in ascending order, where they were the other way round. Swap them in your queries.- Removing all records removes only those that match the query, if there is one.
findOnethrows a 404AngelHttpExceptionwhen no record matches, where it returned{}.modifyandupdateof an id with no record throw a 404AngelHttpException, where they created the record. Usecreateto add one.- Ids: the
idof the data given tocreate,modifyandupdateis not stored, as it is the key of the record;idin a query matches the key. - Requires
angel3_framework10.