deleteDocument method
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);
}