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

abler-db

v1.0.80

Published

数据库相关工具

Readme

彭彭自用包:abler-db

数据库访问相关工具库

安装

npm i abler-db@latest -s

引用

const {db, dbUtil, Redis, redisSimulator, kvStorage} = require("abler-db");
dbUtil.config(conf, err);
kvStorage.config(conf, err).setRedis(new redisSimulator(dbSql));

更新日志

1.0.55

redisSimulator 增加 ttl 函数

1.0.53

SQL脚本可支持条件语句(以 -- @condition 开头),条件语句返回结果求值为true时才执行下一条SQL

1.0.50

完善查询参数后缀规则与范围查询规范,like 自动添加通配符,可以用*代替%, [_from,_to] 修正为 [_from,_to),同时增加[_min,_max],_gt,_gte,_lt,_lte,_not

1.0.47

SQL查询条件根据参数自动添加 like, <> , >=, <=, in

1.0.43

重组SQL语句清理流程,修复Bug

1.0.40

SqlUtil cleanSqlBlock() 支持嵌套块

1.0.33

SqlLoader 改为 SqlUtil,装入SQL文件时支持 --$include 指令

1.0.32

增加 SqlLoader 类

1.0.28

redis包升级,修改配置,支持双向ssl连接

1.0.27

清理SQL语句的Where子句时,可以清除包含无效占位符的 OR (...) 条件了

1.0.26

Bug修复,解决执行SQL报错时找不到错误信息问题

1.0.25

完善dbUtil.executeScript,执行SQL脚本时跳过无有效SQL的语句

1.0.24

修复Bug: 解决数据库更新脚本为js时无法动态加载的问题

1.0.23

修复Bug

1.0.22

删除了没有用到的依赖

1.0.21

数据库版本升级脚本支持js

1.0.20

解决不同方言执行update和delete语句返回属性名称不同,从而导致获取作用行数失败的问题

1.0.13

修改达梦数据库方言:

  • 查询返回结果 BLOB 字段自动返回数据到 Buffer
  • 解决提交大型数据时,报 “跨事务挺重大数据” 问题

1.0.12

完善 DbVersionManager,实现在没有创建数据库的情况下,全自动完成从创建数据库开始的历次数据库版本更新,应用系统配合脚本检查可从安装开始全自动到达服务提供状态

完善 sequelizeCustomizer

1.0.10

执行SQL语句前,根据配置或参数数据类型确定 sequelize 参数传递方式(是否强制Bind参数)

1.0.3~1.09

废弃

1.0.2

增加 Sequelize 方言定制功能,支持达梦数据库,同时修正MySql相关代码,使之支持 createSchema ,tabelExists等函数

版本1.0.2更新注意事项

应用配置部分配置项改名
envSettings.xxx.dbname >> ...dbName
envSettings.xxx.dbuser >> ...dbUser

envSettingNotes.dbname >> ...dbName
envSettingNotes.dbuser >> ...dbUser

conf.dbconn  >>  conf.dbConf
conf.dbconn.dbname  >>  conf.dbConf.dbName
conf.dbconn.dbuser  >>  conf.dbConf.dbUser
envSetting.dbname  >>  envSetting.dbName
envSetting.dbuser  >>  envSetting.dbUser
关于 SQL 语句配置文件

之前的SQL语句是写在 config 目录中的 dbsql.js 的 class dbSql 中,没有区分数据库类型,现在要求 dbsql.js 输出一个 dbSqls 对象,按数据库类型组织SQL语句:

class dbSql_MySql {
    static API_LOG_QUERY = `
    SELECT    
        ID as id,
        ......
    FROM ~dbOwner~API_REQUEST_LOG
    WHERE true
        AND ID = :id
        ......
    `
}
class dbSql_dm {
    static API_LOG_QUERY = `
    SELECT
        ......
    `
}
const dbSqls = {
    MySql: dbSql_MySql,
    dm: dbSql_dm,
}
module.exports = dbSqls;

同时在 config.js 的 config 中包含 dbSql:

let config = {
	......
    dbSql: dbSqls.MySql, // 默认,系统初始化时根据配置可能重新设置
	......
}
增加 DbVersionManager 管理应用系统的数据库版本

应用配置增加 conf.appSetting.dbVersionControl,其内容来自原来的 dbupdate/dd-version.js,有所简化,示例:

appSetting: {
	......
    dbVersionControl: {
        autoUpdate: false, //是否自动执行更新脚本
        currentVersion: 2, //当前版本,目标部署环境中,最后更新的数据库版本必须与此相符,否则系统无法正常运行
        versions: {
            "1": {
                info: "初始化数据库",
                upScript: "1-dbinit.sql"
            },
            "2": {
                info: "增加三个测试表",
                upScript: "2-up.sql"
            }
        }
    },
    ......

各版本的SQL脚本文件(上例中的 1-dbinit.sql 和 2-up.sql )仍然保存在 dbupdate 目录,其内容也只写业务相关的SQL,不需要写更新创建schema和维护DD_VERSION表的SQL,如:

文件 1-dbinit.sql:

-- ============================
-- v1, 2025.01.25

-- 增加API访问记录表
CREATE TABLE "{schema}".API_REQUEST_LOG (
    ID VARCHAR(32) NOT NULL,
    REQ_TIME TIMESTAMP(3), -- DATETIME(3) 转为 TIMESTAMP(3)
    API_KEY VARCHAR(32),
    USER_ID VARCHAR(32),
    FROM_IP VARCHAR(45),
    USER_AGENT VARCHAR(50), -- nvarchar 转为 varchar
    METHOD VARCHAR(10),
    ENDPOINT VARCHAR(100), -- nvarchar 转为 varchar
    REQ_PARAMS CLOB, -- LongText 转为 CLOB
    RES_CODE INT,
    RES_INFO VARCHAR(200), -- nvarchar 转为 varchar
    RES_BODY CLOB, -- LongText 转为 CLOB
    DURATION INT,
    LST_UPD_DT DATETIME(3),
    PRIMARY KEY (ID)
)
;

-- 键值对表,每项键值对都有过期时间,缺省为1天
CREATE TABLE "{schema}".KV_PAIR (
  KP_KEY VARCHAR(100) NOT NULL,
  KP_VALUE CLOB,                    -- 达梦大文本用CLOB替代TEXT
  EXPIRE_AT DATETIME(3) DEFAULT DATEADD(DAY, 1, CURRENT_TIMESTAMP), -- 默认过期时间1天
  LST_UPD_DT DATETIME(3),
  PRIMARY KEY (KP_KEY)
);

INSERT INTO "{schema}".KV_PAIR VALUES (
  'keyX',
  'valueX of keyX',
  DATEADD(DAY, 1, CURRENT_TIMESTAMP),
  sysdate()
);

文件 2-up.sql:

-- ============================
-- v2, 2025.01.26

CREATE TABLE "{schema}".TEST1 (
    ID VARCHAR(32) NOT NULL,
    TEST_FIELD1 VARCHAR(32),
    PRIMARY KEY (ID)
);

CREATE TABLE "{schema}".TEST2 (
    ID VARCHAR(32) NOT NULL,
    TEST_FIELD1 VARCHAR(32),
    PRIMARY KEY (ID)
);

CREATE TABLE "{schema}".TEST3 (
    ID VARCHAR(32) NOT NULL,
    TEST_FIELD1 VARCHAR(32),
    PRIMARY KEY (ID)
)

版本1.0.1无效发布,废弃

由于.git 损坏,修复过程中误操作导致部分修改的代码丢失,发布的这个版本无法使用。