AppstraxDatabase class

Reads and writes documents in your Appstrax collections.

Collections are registered, not created by writing to them

A collection has to exist in the admin panel before this service can touch it. Writing to a name nobody registered answers NotFoundException rather than creating it, so that is the first thing to check when a call 404s on a collection you expected to be there. Collections that already held data when the API was upgraded were registered automatically, so existing applications are unaffected.

Every collection carries a policy

An administrator decides, per collection, who may read, create, update and delete, and which fields each of those may touch. This SDK cannot read or change a policy - that is the admin panel's job - so the errors below are the only way a policy makes itself known:

Exception Meaning
ForbiddenException The policy denies this operation, or a field the body carried. Not a session problem: do not sign the user out.
ConflictException The document changed while you were writing it. Re-read it, apply the change again, and send it.
NotFoundException The document does not exist, is hidden from you by the policy, or the collection is not registered. Deliberately indistinguishable - a policy must not reveal what it is hiding.
BadRequestException A field the policy does not let you write, or a where/order clause the API rejected. body names the offending field.

Branch on the type rather than on code. For a policy failure the API sends prose - Insufficient Permissions - not one of the machine-readable constants the auth endpoints use.

A read may also come back with fields missing, where the policy allows the document but not every field on it. DocumentDto.data is a map and copes; a model of your own with required non-nullable fields will not.

Constructors

AppstraxDatabase()
factory

Properties

config Config
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
http HttpService
Replaced by initializeAppstraxServices, and by tests with a client that answers without a server. The default keeps the service usable on its own.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

create(String collection, Map<String, dynamic> data) Future<DocumentDto>
delete(String collection, String id) Future<void>
documentUrl(String collection, [String? id]) String
The URL for a collection, or for one document in it.
edit(String collection, String id, Map<String, dynamic> data) Future<DocumentDto>
Updates one document.
find(String collection, {FetchQuery? query}) Future<FindResultDto>
A page of documents from collection.
findById(String collection, String id) Future<DocumentDto>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited