
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
此包为达梦数据库驱动 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数组的可选值为:'DATE', 'NUMBER', 'BUFFER', 'CLOB'。
const knex = require('knex')({
client: require('knex-dm'),
connection: {
/*...*/
},
fetchAsString: ['number', 'clob'],
});
在数据库驱动执行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;
},
});
指定方言包向其他数据库方言包兼容,默认兼容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}) // 执行成功
compatible兼容mysql的特性
sqlTransformer、compatibleFAQs
DM database dialect for knex.js
We found that knex-dm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.