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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zhaojiu/km-mysql

v1.0.0

Published

A key management library using MySQL

Readme

km-mysql

一个基于 MySQL 的密钥管理库,提供简单而强大的密钥存储和管理功能。

功能特点

  • 基于 MySQL 数据库的密钥存储
  • 支持密钥的增删改查操作
  • 支持密钥版本管理
  • 简单易用的 API 接口
  • 完整的类型支持
  • 异步操作支持

安装

使用 npm 安装:

npm install km-mysql

基本使用

1. 初始化连接

const KMMySQL = require('km-mysql');

const config = {
  host: 'localhost',
  user: 'your_username',
  password: 'your_password',
  database: 'your_database'
};

const km = new KMMySQL(config);

2. 创建密钥

// 创建新密钥
await km.createKey('my-key', 'my-secret-value');

// 创建带有元数据的密钥
await km.createKey('my-key', 'my-secret-value', {
  description: '这是一个测试密钥',
  tags: ['test', 'demo']
});

3. 获取密钥

// 获取最新版本的密钥
const key = await km.getKey('my-key');

// 获取指定版本的密钥
const keyVersion = await km.getKeyVersion('my-key', 1);

4. 更新密钥

// 更新密钥值(自动创建新版本)
await km.updateKey('my-key', 'new-secret-value');

// 更新密钥元数据
await km.updateKeyMetadata('my-key', {
  description: '更新后的描述',
  tags: ['updated', 'test']
});

5. 删除密钥

// 删除密钥(包括所有版本)
await km.deleteKey('my-key');

// 删除指定版本的密钥
await km.deleteKeyVersion('my-key', 1);

6. 列出密钥

// 获取所有密钥
const keys = await km.listKeys();

// 获取密钥的所有版本
const versions = await km.listKeyVersions('my-key');

高级用法

标签和元数据

您可以为密钥添加标签和元数据,以便更好地组织和管理:

// 创建带有标签和元数据的密钥
await km.createKey('api-key', 'secret-value', {
  description: 'API访问密钥',
  tags: ['api', 'production'],
  metadata: {
    environment: 'production',
    team: 'backend',
    expiry: '2024-12-31'
  }
});

// 按标签搜索密钥
const apiKeys = await km.findKeysByTag('api');

版本管理

km-mysql 提供了内置的版本管理功能:

// 获取所有版本
const versions = await km.listKeyVersions('my-key');

// 获取特定版本
const version2 = await km.getKeyVersion('my-key', 2);

// 回滚到特定版本
await km.rollbackToVersion('my-key', 2);

错误处理

km-mysql 使用标准的错误处理机制:

try {
  await km.getKey('non-existent-key');
} catch (error) {
  if (error.code === 'KEY_NOT_FOUND') {
    console.error('密钥不存在');
  } else {
    console.error('发生错误:', error);
  }
}

API 参考

主要方法

  • createKey(keyName, value, options?): 创建新密钥
  • getKey(keyName): 获取密钥的最新版本
  • getKeyVersion(keyName, version): 获取特定版本的密钥
  • updateKey(keyName, newValue): 更新密钥值
  • updateKeyMetadata(keyName, metadata): 更新密钥元数据
  • deleteKey(keyName): 删除密钥
  • deleteKeyVersion(keyName, version): 删除特定版本的密钥
  • listKeys(): 列出所有密钥
  • listKeyVersions(keyName): 列出密钥的所有版本
  • findKeysByTag(tag): 按标签搜索密钥

配置选项

{
  host: string;          // MySQL 主机地址
  user: string;          // 用户名
  password: string;      // 密码
  database: string;      // 数据库名
  port?: number;         // 端口号(默认:3306)
  connectionLimit?: number; // 连接池大小(默认:10)
}

许可证

MIT

作者

彭振辉