NoSqlDatabase class

Class for building a NoSql database model within an application.

It is based on the Firestore model and handles data separately as documents and collections.

https://firebase.google.com/docs/firestore/data-model

Use loadDocument to read individual data and loadCollection to read a collection of data.

You can pass ModelAdapterDocumentQuery on each data read and specify callbacks when data is updated internally.

This makes it possible to monitor changes that occur elsewhere (or outside the application, such as on the server side) and to handle data in sync with the database.

Data can be added (updated) and deleted only in documents. Use saveDocument and deleteDocument respectively.

Callbacks for onInitialize, onLoad, onSaved, and onDeleted can be passed when an object is created, making it possible to add processing that links with external databases, etc. when data is read or saved.

When a document or collection is destroyed, use removeDocumentListener and removeCollectionListener to remove each document or collection from the monitoring target.

アプリケーション内でのNoSqlデータベースモデルを構築するためのクラスです。

Firestoreのモデルをベースとしており、ドキュメントとコレクションに分けてデータを扱います。

https://firebase.google.com/docs/firestore/data-model

個別のデータの読み取りはloadDocumentを利用し、まとまったデータの読み取りはloadCollectionを利用します。

それぞれのデータ読み取り時にModelAdapterDocumentQueryを渡すことができ、データが内部で更新された場合のコールバックを指定できます。

これにより他の箇所で起きた(もしくはサーバー側などのアプリ外)変更を監視することが可能になりデータベースと同期したデータを扱うことができます。

データの追加(更新)、削除はドキュメントのみで行うことが可能です。それぞれsaveDocumentdeleteDocumentで行います。

オブジェクトの作成時にonInitializeonLoadonSavedonDeletedのコールバックを渡すことができ、データの読み出し時や保存時などに外部のデータベース等との連携処理を追加することが可能です。

ドキュメントやコレクションが破棄される際はremoveDocumentListenerremoveCollectionListenerで各ドキュメントやコレクションを監視対象から外してください。

Constructors

NoSqlDatabase({Future<void> onInitialize(NoSqlDatabase database)?, Future<void> onLoad(NoSqlDatabase database)?, Future<void> onSaved(NoSqlDatabase database)?, Future<void> onDeleted(NoSqlDatabase database)?, Future<void> onClear(NoSqlDatabase database)?})
Class for building a NoSql database model within an application.

Properties

data DynamicMap
Location where real data is stored.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isInitialValueRegistered bool
Returns true if data is registered with setInitialValue.
no setter
onClear Future<void> Function(NoSqlDatabase database)?
Executed when all Database is deleted.
final
onDeleted Future<void> Function(NoSqlDatabase database)?
Executed when Database is deleted.
final
onInitialize Future<void> Function(NoSqlDatabase database)?
Executed at Database initialization time.
final
onLoad Future<void> Function(NoSqlDatabase database)?
Executed when loading Database.
final
onSaved Future<void> Function(NoSqlDatabase database)?
Executed when saving the Database.
final
registeredInitialValuePaths List<String>
Returns a list of registered initial value paths.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearAll() Future<void>
Delete all data.
deleteDocument(ModelAdapterDocumentQuery query, {String? prefix}) Future<void>
Deletes the data in the document corresponding to query by passing query.
getInitialCollection(ModelAdapterCollectionQuery query, {String? prefix}) Future<Map<String, DynamicMap>?>
Load the document corresponding to query from _registeredInitialValue.
getInitialDocument(ModelAdapterDocumentQuery query, {String? prefix}) Future<DynamicMap?>
Load the document corresponding to query from _registeredInitialValue.
loadCollection(ModelAdapterCollectionQuery query, {String? prefix}) Future<Map<String, DynamicMap>?>
Pass query and load the collection corresponding to query.
loadDocument(ModelAdapterDocumentQuery query, {String? prefix}) Future<DynamicMap?>
Pass query and load the document corresponding to query.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyDocuments(String documentPath, String documentId, DynamicMap value, ModelUpdateNotificationStatus status, ModelAdapterDocumentQuery query) → void
Sends notifications to monitored documents and collections based on documentPath and documentId.
removeCollectionListener(ModelAdapterCollectionQuery? query, {String? prefix}) → void
Pass query to remove the collection corresponding to query from the monitored list.
removeDocumentListener(ModelAdapterDocumentQuery? query, {String? prefix}) → void
Pass query to remove the document corresponding to query from the monitored list.
replace(DynamicMap replaceData) Future<void>
Replaces all data in the database inside by giving replaceData.
saveCollection(ModelAdapterCollectionQuery query, Map<String, DynamicMap> value, {String? prefix}) Future<void>
Update and add data from the collection corresponding to query to value by passing query.
saveDocument(ModelAdapterDocumentQuery query, DynamicMap value, {String? prefix}) Future<void>
Update and add data to value by passing query and the data in the document corresponding to query.
setInitialValue(String path, DynamicMap value) → void
Add/update the data of value at the position of path.
syncCollection(ModelAdapterCollectionQuery query, Map<String, DynamicMap>? value, {String? prefix}) Future<Map<String, DynamicMap>?>
Stores value in the path corresponding to query and then returns value.
syncDocument(ModelAdapterDocumentQuery query, DynamicMap? value, {String? prefix}) Future<DynamicMap?>
Stores value in the path corresponding to query and then returns value.
toString() String
A string representation of this object.
inherited

Operators

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