NoSqlDatabase constructor

NoSqlDatabase({
  1. Future<void> onInitialize(
    1. NoSqlDatabase database
    )?,
  2. Future<void> onLoad(
    1. NoSqlDatabase database
    )?,
  3. Future<void> onSaved(
    1. NoSqlDatabase database
    )?,
  4. Future<void> onDeleted(
    1. NoSqlDatabase database
    )?,
  5. Future<void> onClear(
    1. NoSqlDatabase database
    )?,
})

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, onDeleted, and onClear can be passed when creating an object, allowing for additional processing in conjunction with an external database, etc. when reading or saving data.

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で行います。

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

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

Implementation

NoSqlDatabase({
  this.onInitialize,
  this.onLoad,
  this.onSaved,
  this.onDeleted,
  this.onClear,
});