Appearance
软删除
¥Soft-delete
Who maintains the package
- Jam
这是个什么包?
¥What is this package?
软删除是向 Meteor 应用添加软删除功能的简便方法。其主要功能如下:
¥Soft Delete is an easy way to add soft deletes to your Meteor app. Its key features are:
无需任何配置(但你可以自定义)
¥Zero config needed (though you can customize)
同构,以便与 Optimistic UI 兼容
¥Isomorphic so that it works with Optimistic UI
自动覆盖
removeAsync
以使其成为软删除¥Automatically overrides
removeAsync
to make it a soft delete自动在
insertAsync
上以及查询过滤器中添加软删除标志,例如.find
,因此你无需对其进行任何更改¥Automatically adds the soft delete flag on
insertAsync
and to the filter for your queries, e.g..find
, so you don't need to make any changes to them使用
recoverAsync
收集方法恢复软删除的文档¥Recover soft deleted docs with
recoverAsync
collection method使用
softRemoveAsync
收集方法显式软删除(可选)¥Explicitly soft delete with
softRemoveAsync
collection method (optional)可选择添加
deletedAt
时间戳¥Optionally add a
deletedAt
timestamp(可选)排除特定集合
¥Optionally exclude specific collections
兼容 Meteor
2.8.1+
和3.0+
¥Compatible with Meteor
2.8.1+
and3.0+
注意:软删除的替代方法是将文档归档到你的集合中。你可以使用
jam:archive
包来实现这一点。请务必比较这两种方法,以选择最适合你应用的解决方案。¥Note: Alternative to soft deletion is to archive documents in your collection. You can use
jam:archive
package for that. Be sure to compare those two approaches to pick the solution best suited for your application.
如何下载?
¥How to download it?
将软件包添加到你的应用
¥Add the package to your app
bash
meteor add jam:soft-delete
来源
¥Sources
如何使用?
¥How to use it?
永久删除
¥Deleting permanently
默认情况下,此包会覆盖 removeAsync
集合方法,以便使用布尔标志软删除文档,而不是将其从数据库中移除。要永久删除,请传入选项 soft: false
,例如:
¥By default, this package overrides the removeAsync
collection method so that it soft deletes the document(s) with a boolean flag rather that removing them from the database. To delete permanently, pass in the option soft: false
, e.g.:
js
Collection.removeAsync(/* your filter */, { soft: false })
如果你愿意,可以通过设置 overrideRemove: false
来防止覆盖 removeAsync
。有关更多详细信息,请参阅 配置。
¥If you prefer, you can prevent overriding the removeAsync
by setting overrideRemove: false
. See Configuring for more details.
显式软删除
¥Explicitly soft deleting
如果你愿意,可以明确使用 softRemoveAsync
,例如:
¥If you prefer, you can explicity use softRemoveAsync
, e.g.:
js
Collection.softRemoveAsync(/* your filter */)
恢复文档
¥Recovering a document
要恢复软删除的文档,请使用 recoverAsync
,例如:
¥To recover a soft deleted document, use recoverAsync
, e.g.:
js
Collection.recoverAsync(/* your filter */)
配置(可选)
¥Configuring (optional)
如果你喜欢默认设置,则无需配置任何内容。但使用此包的方式有一定的灵活性。
¥If you like the defaults, then you won't need to configure anything. But there is some flexibility in how you use this package.
以下是全局默认值:
¥Here are the global defaults:
js
const config = {
deleted: 'deleted', // the field name used for the boolean flag. you can update to your preference, e.g. 'isDeleted'
deletedAt: '', // add the name of the field you'd like to use for a deletedAt timestamp, e.g. 'deletedAt', if you want to include it on your docs
autoFilter: true, // automatically adds the { [deleted]: false } filter to your queries
overrideRemove: true, // overrides the Collection.removeAsync method to make it a soft delete instead
exclude: ['roles', 'role-assignment'] // exclude specific collections from using soft delete. defaults to excluding the collections created the meteor roles package
};
要更改全局默认值,请使用:
¥To change the global defaults, use:
js
// put this in a file that's imported on both the client and server
import { SoftDelete } from 'meteor/jam:soft-delete';
SoftDelete.configure({
// ... change the defaults here ... //
});