Appearance
归档
¥Archive
Who maintains the package
- Jam
这是个什么包?
¥What is this package?
归档是为你的 Meteor 应用添加归档机制的简便方法。文档存档后,它会从其原始集合中移除并放置在存档集合中,以便在需要时恢复。其主要功能如下:
¥Archive is an easy way to add an archive mechanism to your Meteor app. When a document is archived, it's removed from its original collection and placed in an archive collection so that it can be restored if needed. 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 perform an archive (can be turned off)使用
archiveAsync
收集方法显式归档(可选)¥Explicitly archive with
archiveAsync
collection method (optional)使用
restoreAsync
集合方法恢复已归档的文档¥Restore archived docs with
restoreAsync
collection method(可选)排除特定集合
¥Optionally exclude specific collections
兼容 Meteor
3.0.2+
¥Compatible with Meteor
3.0.2+
注意:软删除的替代方案是归档你的集合中的文档。你可以使用
jam:soft-delete
包来实现这一点。请务必比较这两种方法,以选择最适合你应用的解决方案。¥Note: Alternative to archive is soft deletion. You can use
jam:soft-delete
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:archive
来源
¥Sources
如何使用?
¥How to use it?
创建你的存档集合
¥Create your Archives collection
在你的应用中创建一个 Archive 集合,就像创建其他集合一样。
¥Create an Archives collection in your app just as you would any other collection.
js
const Archives = new Mongo.Collection('archives');
Archives 集合中的文档将具有以下结构:
¥Documents in the Archives collection will have this shape:
js
{
_id, // auto-generated by Meteor as with other collection _ids
_collection, // the name of the collection, e.g. 'todos', that the doc belonged to originally
archivedAt, // the timestamp when the document was removed from its original collection and inserted into the archive
id, // the original doc _id renamed to prevent conflict with the auto-generated one above. when restored, it will be renamed back to _id automatically by this package
/*
...rest of original doc
*/
}
永久删除
¥Deleting permanently
默认情况下,此包会覆盖 removeAsync
的集合方法,以便归档文档,而不是将其从数据库中删除。要永久删除,请传入选项 forever: true
,例如:
¥By default, this package overrides the removeAsync
collection method so that it archives the document(s) rather that removing them from the database. To delete permanently, pass in the option forever: true
, e.g.:
js
Collection.removeAsync(/* your filter */, { forever: true })
如果你愿意,可以通过设置 overrideRemove: false
来防止覆盖 removeAsync
。有关更多详细信息,请参阅 配置。
¥If you prefer, you can prevent overriding the removeAsync
by setting overrideRemove: false
. See Configuring for more details.
显式归档
¥Explicitly archiving
如果你愿意,可以明确使用 archiveAsync
,例如:
¥If you prefer, you can explicity use archiveAsync
, e.g.:
js
Collection.archiveAsync(/* your filter */)
还原文档
¥Restoring a document
要恢复已归档的文档,请使用 restoreAsync
,例如:
¥To restore an archived document, use restoreAsync
, e.g.:
js
Collection.restoreAsync(/* 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 = {
name: 'archives', // if your Archives collection uses a different name, you'll want to change this
overrideRemove: true, // overrides the Collection.removeAsync method to make it an archive instead
exclude: ['roles', 'role-assignment'] // exclude specific collections from using archive so that when they are removed, the are permanently removed from the db. defaults to excluding the collections created by 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 { Archive } from 'meteor/jam:archive';
Archive.configure({
// ... change the defaults here ... //
});