npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hc-storage-toolkit-base-model

v0.0.2

Published

A base model for HC Storage System.

Readme

hc-storage-toolkit-base-model

功能特性

  • 负责数据库的操作和归档: 提供强数据库操作(支持重试、使用队列执行),并提供归档任务。

安装

确保已安装 Node.js,然后向您的项目中添加 hc-storage-toolkit-base-model 包:

npm install hc-storage-toolkit-base-model

使用方法

引入模块

const hcStorageAdapter = require('hc-storage-toolkit-base-model');
const { BaseModel } = hcStorageAdapter;

or

import { BaseModel } from 'hc-storage-toolkit-base-model';

初始化

通过传递一个包含必要配置的对象来实例化 BaseModel 类:

class MissionModel extends BaseModel {
  /**
   * 构造函数
   * @param {string} mission 
   */
  constructor(collectionName) {
    super(collectionName);
    // 如果需要开启归档任务,需要调用此方法
    this.loadRegularArchive();
  }
}

方法

loadRegularArchive()

如果需要开启归档任务,需要调用此方法

handleArchiveJobError(error, regularArchiveInstance)

可以覆写此方法,处理归档任务的错误

find(query, skips = 0, pageSize = 0, sort = { _id: -1 })

查询数据

findOne(query, options = {})

查询单个数据

findOneAndUpdate(query, doc, options = {})

查询单个数据并更新

findOneWithinManyAndUpdateOne(query, doc, options = {})

查询单个数据并更新第一个符合条件的

updateOne(query, doc, options = {})

更新单个数据

updateMany(query, doc, options = {})

更新多个数据

update(query, doc, options = {})

更新数据

findAll(query)

查询所有数据

aggregate(query)

聚合查询

count(query)

统计数据

create(doc, options = {})

创建数据

createMany(docs, options = {})

创建多个数据

remove(query, options = {})

删除数据

removeMany(query, options = {})

删除多个数据

removeAll()

删除整个集合

配置

在实例化时传递的配置对象支持以下属性:

  • config: 归档过程的配置选项。
    • archiveDays: 归档天数,默认 31 天,配置格式为 { mission: 31, dbLogger: 31 }
    • archiveDataChunkSize: 归档数据块大小,默认 3000 条
    • allowArchiveInRunningMode: 是否允许在运行模式下归档,默认 false
  • archiveScheduleRule: 归档调度规则,CRON 表达式,默认每天凌晨1点10分整(01:10:00)执行
  • archiveOptions: 特定于归档查询和参数的选项。
  • handleArchiveJobError: 错误处理的回调函数。

archiveScheduleRule 说明

archiveScheduleRule 是定义归档任务调度规则的对象。此规则指定了任务执行的具体时间。 例如,如果你希望每天的凌晨 1 点执行归档任务,可以设置 archiveScheduleRule 如下:

0 0 1 * * ?

开发

安装依赖

npm install

构建项目

npm run build

发布

npm publish

贡献

欢迎提交 Issue 和 Pull Request 来贡献代码。

许可证

ISC


请确认是否需要进一步修改或补充信息。