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

koishi-plugin-database-jsondb

v1.0.1

Published

JSON DB database service for Koishi

Readme

koishi-plugin-database-jsondb

基于 JSON 文件的 Koishi 数据库服务。

特性

  • 轻量级: 无外部数据库依赖,非常适合小型机器人。
  • 易于使用: 配置简单,即插即用。

说明

数据库文件默认存放于 data/database/jsondb/*.json

json文件会以表的名称命名

使用方法

完整用法请参考koishi文档 -> koishi.chat/zh-CN/guide/database

在你的插件中使用

import { Context } from 'koishi'

// 声明你需要用到的数据表结构
declare module 'koishi' {
  interface Tables {
    demo: DemoTable
  }
}

export interface DemoTable {
  userid: string
  // ... 其他字段
}

export const inject = ['database']

export async function apply(ctx: Context) {
  // 为 "demo" 表扩展模型
  ctx.model.extend('demo', {
    userid: 'string', // 用户 ID
    // ... 其他字段
  }, {
    primary: ['userid'], // 设置主键
  })

  ctx.middleware(async (session, next) => {
    let userId = session.userId
    if (!userId) return next()

    // 尝试从数据库中获取用户记录
    let [userRecord] = await ctx.database.get('demo', { userid: userId })

    // 如果记录不存在,则创建一条新记录
    if (!userRecord) {
      userRecord = {
        userid: userId,
        // ... 初始化其他字段
      }
      await ctx.database.create('demo', userRecord)
    }

    // 现在你可以使用 userRecord 对象了
    // ...
    
    return next()
  })
}