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

mm_sqlite

v1.2.9

Published

高性能SQLite数据库操作模块,提供与mm_mysql完全兼容的API接口,支持异步操作、事务处理和批量操作

Readme

mm_sqlite

中文 | English

高性能SQLite数据库操作模块,提供与mm_mysql完全兼容的API接口。适用于Node.js应用的轻量级数据存储解决方案。

安装

npm install mm_sqlite --save

特性

  • 🚀 高性能优化:经过深度优化的SQL构建器和连接管理
  • 🔄 完全兼容:与mm_mysql模块API完全兼容,可无缝切换
  • 📊 内存优化:优化的内存使用,减少GC压力
  • 🔧 链式调用:流畅的SQL构建器链式调用
  • 🛡️ 错误处理:完善的错误处理机制
  • 📈 连接池支持:支持连接池模式,提高并发性能
  • 🔒 事务支持:完整的事务处理机制
  • 🔍 类型安全:完善的JSDoc类型注释

依赖要求

  • Node.js 14.0+
  • SQLite3 3.0+

快速开始

基本使用

初始化和连接

const { Sqlite } = require('mm_sqlite');

// 创建数据库实例
const sqlite = new Sqlite({
    dir: './db/',                  // 数据库文件存储目录
    database: 'test',              // 数据库文件名(不包含扩展名)
    charset: 'utf8mb4',            // 字符集
    timezone: '+08:00',            // 时区
    connect_timeout: 20000,        // 连接超时时间(毫秒)
    acquire_timeout: 20000,        // 获取连接超时时间(毫秒)
    query_timeout: 20000,          // 查询超时时间(毫秒)
    connection_limit: 1,           // 连接限制(>1启用连接池)
    enable_keep_alive: true,       // 启用保活
    keep_alive_initial_delay: 10000, // 保活初始延迟
    enable_reconnect: true,        // 启用重连
    reconnect_interval: 1000,      // 重连间隔
    max_reconnect_attempts: 5,     // 最大重连尝试次数
    wait_for_connections: true,    // 等待连接
    pool_min: 1,                   // 连接池最小连接数
    pool_max: 5,                   // 连接池最大连接数
    pool_acquire_timeout: 30000,   // 连接池获取超时
    pool_idle_timeout: 60000,      // 连接池空闲超时
    pool_reap_interval: 1000       // 连接池清理间隔
});

// 打开数据库连接
await sqlite.open();

基础操作

// 获取数据库管理器
const db = sqlite.db();

// 设置表名
const userDb = db.new('users', 'id');

// 插入数据
const result = await userDb.add({
    username: '张三',
    email: '[email protected]',
    age: 28,
    created_at: new Date()
});

// 查询数据
const users = await userDb.get();

// 更新数据
await userDb.set({ id: 1 }, { age: 29 });

// 删除数据
await userDb.del({ id: 1 });

高级查询

// 条件查询
const adultUsers = await userDb.get({
    age: { _gte: 18 }
});

// 分页查询
const pageUsers = await userDb.get({
    _page: 1,
    _size: 10,
    _sort: 'created_at desc'
});

// 聚合查询
const stats = await userDb.aggr({
    _count: 'id',
    _avg: 'age',
    _max: 'age',
    _min: 'age'
});

API参考

Sqlite类

构造函数

new Sqlite(config)

主要方法

  • open() - 打开数据库连接
  • close() - 关闭数据库连接
  • db() - 获取数据库管理器实例
  • run(sql, params) - 执行查询SQL
  • exec(sql, params) - 执行非查询SQL

DB类

表操作

  • addTable(table, field, type, auto, commit, timeout) - 创建表
  • dropTable(table, timeout) - 删除表
  • renameTable(table, new_table, timeout) - 重命名表
  • emptyTable(table, timeout) - 清空表
  • hasTable(table, timeout) - 检查表是否存在

字段操作

  • addField(field, type, value, not_null, auto, comment, timeout) - 添加字段
  • delField(table, field, timeout) - 删除字段
  • renameField(table, field, new_field, type, timeout) - 重命名字段
  • editField(table, field, type, timeout) - 修改字段
  • fields(table, field_name, timeout) - 获取字段信息

数据操作

  • add(data, timeout) - 插入数据
  • set(where, data, timeout) - 更新数据
  • del(where, timeout) - 删除数据
  • get(where, timeout) - 查询数据
  • getTableData(table, batchSize, timeout) - 获取表数据

事务操作

  • start() - 开始事务
  • commit(transaction) - 提交事务
  • back(transaction) - 回滚事务
  • transaction(callback) - 事务中执行操作

配置参数

| 参数 | 类型 | 默认值 | 描述 | |------|------|--------|------| | dir | string | './db/' | 数据库文件存储目录 | | database | string | 'mm' | 数据库文件名 | | charset | string | 'utf8mb4' | 字符集 | | timezone | string | '+08:00' | 时区 | | connect_timeout | number | 20000 | 连接超时时间(ms) | | acquire_timeout | number | 20000 | 获取连接超时时间(ms) | | query_timeout | number | 20000 | 查询超时时间(ms) | | connection_limit | number | 1 | 连接限制 | | enable_keep_alive | boolean | true | 启用保活 | | keep_alive_initial_delay | number | 10000 | 保活初始延迟(ms) | | enable_reconnect | boolean | true | 启用重连 | | reconnect_interval | number | 1000 | 重连间隔(ms) | | max_reconnect_attempts | number | 5 | 最大重连尝试次数 | | wait_for_connections | boolean | true | 等待连接 | | pool_min | number | 1 | 连接池最小连接数 | | pool_max | number | 5 | 连接池最大连接数 | | pool_acquire_timeout | number | 30000 | 连接池获取超时(ms) | | pool_idle_timeout | number | 60000 | 连接池空闲超时(ms) | | pool_reap_interval | number | 1000 | 连接池清理间隔(ms) |

开发规范

  • 使用JavaScript开发,禁止使用TypeScript
  • 使用JSDoc注释进行类型定义
  • 遵循统一的命名规范和方法签名
  • 完善的错误处理机制
  • 支持异步/等待语法

许可证

MIT License

贡献

欢迎提交Issue和Pull Request来改进这个项目。