deleteDocument method

Future<void> deleteDocument(
  1. ModelAdapterDocumentQuery query, {
  2. String? prefix,
})

Deletes the data in the document corresponding to query by passing query.

When deleted, a notification is sent to documents and collections already registered for monitoring according to the data in query.

You can also register a callback for NoSqlDatabase.onDeleted to add processing such as writing out as a file after saving.

prefix can be specified to prefix the path.

queryを渡してqueryに対応するドキュメントのデータを削除します。

削除された場合、queryのデータに応じてすでに監視対象に登録されているドキュメントやコレクションに通知を送信します。

また、NoSqlDatabase.onDeletedのコールバックを登録しておくことで保存後にファイルとして書き出すなどの処理を追加することができます。

prefixを指定するとパスにプレフィックスを付与可能です。

Implementation

Future<void> deleteDocument(
  ModelAdapterDocumentQuery query, {
  String? prefix,
}) async {
  _addDocumentListener(query, prefix: prefix);
  await _initialize();
  final trimPath = _path(query.query.path, prefix);
  final paths = trimPath.split("/");
  if (paths.isEmpty) {
    return;
  }
  data._deleteFromPath(paths, 0);
  notifyDocuments(
    trimPath,
    paths.last,
    {},
    ModelUpdateNotificationStatus.removed,
    query,
  );
  await onDeleted?.call(this);
}