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

minervadb

v1.0.1

Published

A ThinkPHP6-style JavaScript database library based on mysql2 with connection pooling, transactions, and powerful query builder

Readme

MinervaDB — TP6 风格的 JavaScript 数据库库

一个类似 ThinkPHP6 风格的 JavaScript 数据库操作库,基于 mysql2,支持连接池、事务与强大的查询构造器。

特性

  • 🚀 高性能:基于 mysql2 的连接池
  • 💾 事务支持:自动与手动事务 API
  • 🔍 查询构造器:链式调用,功能丰富
  • 📝 TP6 风格 API:使用体验接近 ThinkPHP6
  • 🛡️ 类型安全:参数化查询防止 SQL 注入

安装依赖

npm install
# 或单独安装 mysql2
npm install mysql2

快速开始

const { Database } = require('./lib');

const config = {
  host: '127.0.0.1',
  port: 3306,
  user: 'root',
  password: '123456',
  database: 'test1',
  charset: 'utf8mb4',
  timezone: '+08:00',
  connectionLimit: 10,
  queueLimit: 0
};

const db = new Database(config);
await db.init();

// 使用 query 或 QueryBuilder
const users = await db.table('users').where('age >= ?', 18).limit(10).select();
console.log(users);

await db.close();

运行示例

仓库包含 examples/,两个示例:

  • examples/basic-usage.js:插入/查询/更新示例(展示 raw 使用与 toSql)。
  • examples/transaction.js:演示自动事务。

运行示例(示例会读取仓库根目录的 .env):

node .\examples\basic-usage.js
node .\examples\transaction.js

注意:examples/* 会静默加载 .env(如果存在),库本身不会在 require 时产生副作用。

运行测试

我们为 QueryBuilder 添加了单元测试(Jest),可以通过下面命令运行:

npm install
npm test

主要 API

请参考代码中的 DatabaseQueryBuilder 的方法:

  • init()query()execute()
  • insert()insertAll()update()delete()
  • select()find()count()
  • table() 获取 QueryBuilder
  • 事务:startTransaction()commit()rollback()transaction(callback)

查询构造器示例

// 链式构造
await db.table('users')
  .field(['id','username','email'])
  .where('age >= ?', 18)
  .where({ status: 1 })
  .order('id', 'DESC')
  .limit(10)
  .select();

事务示例

// 自动事务
await db.transaction(async (db) => {
  const id = await db.insert('users', { username: 'u1' });
  await db.insert('profiles', { user_id: id });
});

// 手动事务
await db.startTransaction();
try {
  await db.insert('users', data);
  await db.commit();
} catch (err) {
  await db.rollback();
}

调试 SQL

const sql = db.table('users').where('age >= ?', 18).limit(10).toSql();
console.log(sql);

许可证

MIT