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

knex-dm

v1.0.45146

Published

DM database dialect for knex.js

Downloads

162

Readme

knex-dm

此包为达梦数据库驱动 dmdb 适配 knex 框架的方言包,使用示例如下:

const knex = require('knex')({
    client: require('knex-dm'),
    connection: {
        // 其他可配置的内容见dmdb.ConnectionAttributes
        connectString: 'localhost:5236',
        user: 'SYSDBA',
        password: 'SYSDBA',
        schema: 'SYSDBA1',
    },
    debug: false,
});
await knex.schema.createTable('USERS', (table) => {
    table.increments('ID');
    table.string('USER_NAME');
});
await knex('USERS').insert({"USER_NAME": "Tom"});
await knex.destroy();

方言包扩展内容

配置项 - fetchAsString

指定结果集中的一些数据类型以字符串形式返回,fetchAsString数组的可选值为:'DATE', 'NUMBER', 'BUFFER', 'CLOB'。

const knex = require('knex')({
    client: require('knex-dm'),
    connection: {
        /*...*/
    },
    fetchAsString: ['number', 'clob'],
});

配置项 - sqlTransformer

在数据库驱动执行SQL语句之前,可通过sqlTransformer转变函数修改SQL语句以达到一些目的,如SQL语句兼容,改变数据类型,添加注释等。

const knex = require('knex')({
    client: require('knex-dm'),
    connection: {
        /*...*/
    },
    sqlTransformer: (originSql) => {
        let transformedSql = originSql;
        // 例1:添加注释
        transformedSql = `/* any comment */` + transformedSql;
        // 例2:将cast('123' as char)转变成cast('123' as varchar)以兼容mysql执行结果
        transformedSql = transformedSql.replace(/cast\(([^)]+) as char\)/g, (match, sql) => {
            return `cast(${sql} as varchar)`;
        });
        return transformedSql;
    },
});

配置项 - compatible

指定方言包向其他数据库方言包兼容,默认兼容oracle,目前可选取值为 'mysql',下面介绍兼容具体特性。
兼容mysql
json/jsonb映射为json knex.raw()执行SQL语句,查询结果返回格式从一维数组 [数据] 变为二维数组 [[数据]]。

const knex = require('knex')({
    client: require('knex-dm'),
    connection: {
        /*...*/
    },
    compatible: 'mysql',
});

自增列插入

knex(tableName, options={identityInsert: boolean})
identityInsert: 是否开启自增列插入。由于达梦数据库不支持往自增列中手动插入值,此选项通过在插入语句前添加set identity_insert <table> on;语句以实现手动插入自增列的功能。

knex('test').insert({id: 1}) // 报错:[-2723] 仅当指定列列表,且SET IDENTITY_INSERT为ON时,才能对自增列赋值
knex('test', {identityInsert: true}).insert({id: 1}) // 执行成功

Change Logs

knex-dm v1.0.45146(2025-12-22)

  • 扩充compatible兼容mysql的特性
    • json/jsonb映射为json
  • 支持whereJsonSupersetOf、whereJsonSubsetOf、whereJsonObject

knex-dm v1.0.43524(2025-11-14)

  • 因dmdb绑出参数格式策略调整,同步升级

knex-dm v1.0.36002(2025-05-12)

  • 新增配置项 sqlTransformercompatible
  • 修复createTableIfNotExists报错的问题
  • 修复limit/offset参数列表错误的问题
  • 一些类型映射改动
    • json/jsonb映射从clob改为varchar(4000)
    • binary映射从binary(1)改为blob

knex-dm v1.0.35022(2025-04-08)

  • 修复当数据库登录密码不是SYSDBA时,方言包无法连接数据库的问题

knex-dm v1.0.34946(2025-04-07)

  • 发布正式版,已跑通knex源码测例,主要以兼容ORACLE为主