knex-dm 1.0.34946
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +50 -0
- package/package.json +20 -0
- package/src/index.js +360 -0
- package/src/query/dmdb-querybuilder.js +20 -0
- package/src/query/dmdb-querycompiler.js +612 -0
- package/src/schema/dmdb-columnbuilder.js +17 -0
- package/src/schema/dmdb-columncompiler.js +147 -0
- package/src/schema/dmdb-compiler.js +94 -0
- package/src/schema/dmdb-tablecompiler.js +205 -0
- package/src/schema/dmdb-viewbuilder.js +13 -0
- package/src/schema/dmdb-viewcompiler.js +17 -0
- package/src/transaction.js +83 -0
- package/src/utils.js +280 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
软件产品授权证书
|
|
2
|
+
|
|
3
|
+
重要须知:武汉达梦数据库有限公司提醒您请在安装该软件之前仔细阅读以下许可协议。您一旦安装、下载、访问或以其他方式使用该软件产品,即表明您同意接受本《协议》各条款约束。如果您同意访问该软件产品,请选择“接受”项。如果您不同意本《协议》中的条款,请不要安装、访问或使用该软件产品;但您可将其退回。如果您已访问了该软件产品,请点击“不接受”项,并退出该安装程序。
|
|
4
|
+
|
|
5
|
+
1.本软件的使用、武汉达梦数据库有限公司提供的服务均按照所签订合约来执行。
|
|
6
|
+
|
|
7
|
+
2.本软件版权为武汉达梦数据库有限公司所有,您不能对本软件的任何部分进行修改、分解、反汇编和反编译。
|
|
8
|
+
|
|
9
|
+
3.本软件是已经注册登记并受法律保护的商业软件。它的适用法律包括《中华人民共和国计算机保护法》、《中华人民共和国著作权法》、《中华人民共和国专利法》等。
|
|
10
|
+
|
|
11
|
+
4.不得将本软件转让给他方使用,否则视为违反合约。
|
|
12
|
+
|
|
13
|
+
Dameng Database co., ltd.
|
|
14
|
+
|
|
15
|
+
Software License Agreement
|
|
16
|
+
|
|
17
|
+
READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED SUPPLEMENTAL LICENSE TERMS (COLLECTIVELY "AGREEMENT") CAREFULLY BEFORE OPENING THE SOFTWARE MEDIA PACKAGE. BY OPENING THE SOFTWARE MEDIA PACKAGE, YOU AGREE TO THE TERMS OF THIS AGREEMENT. IF YOU ARE ACCESSING THE SOFTWARE ELECTRONICALLY, INDICATE YOUR ACCEPTANCE OF THESE TERMS BY SELECTING THE "ACCEPT" BUTTON AT THE END OF THIS AGREEMENT.IF YOU DO NOT AGREE TO ALL OF THESE TERMS, PROMPTLY RETURN THE UNUSED SOFTWARE TO YOUR PLACE OF PURCHASE FOR A REFUNDOR, IF THE SOFTWARE IS ACCESSED ELECTRONICALLY, SELECT THE "NOT ACCEPT" BUTTON AT THE END OF THIS AGREEMENT AND THE INSTALLATION PROCESS WILL NOT CONTINUE.
|
|
18
|
+
|
|
19
|
+
1. The use and the services of the software shall remain in the agreement.
|
|
20
|
+
2. DM Database owns all copyrights in the product. You may not modify, decompose, compile, and decompile the product.
|
|
21
|
+
3. The product is registered and protected by PRC copyright and other laws.
|
|
22
|
+
4. You may not allow third parties to access or use the product.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# knex-dm
|
|
2
|
+
|
|
3
|
+
此包为达梦数据库驱动 [dmdb](https://www.npmjs.com/package/dmdb) 适配 [knex](https://www.npmjs.com/package/knex) 框架的方言包,使用示例如下:
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
const knex = require('knex')({
|
|
7
|
+
client: require('knex-dm'),
|
|
8
|
+
connection: {
|
|
9
|
+
// 其他可配置的内容见dmdb.ConnectionAttributes
|
|
10
|
+
connectString: 'localhost:5236',
|
|
11
|
+
user: 'SYSDBA',
|
|
12
|
+
password: 'SYSDBA',
|
|
13
|
+
schema: 'SYSDBA1',
|
|
14
|
+
},
|
|
15
|
+
debug: false,
|
|
16
|
+
});
|
|
17
|
+
await knex.schema.createTable('USERS', (table) => {
|
|
18
|
+
table.increments('ID');
|
|
19
|
+
table.string('USER_NAME');
|
|
20
|
+
});
|
|
21
|
+
await knex('USERS').insert({"USER_NAME": "Tom"});
|
|
22
|
+
await knex.destroy();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 方言包扩展内容
|
|
26
|
+
|
|
27
|
+
### 配置项 - fetchAsString
|
|
28
|
+
指定结果集中的一些数据类型以字符串形式返回,fetchAsString数组的可选值为:'DATE', 'NUMBER', 'BUFFER', 'CLOB'。
|
|
29
|
+
```JS
|
|
30
|
+
const knex = require('knex')({
|
|
31
|
+
client: require('knex-dm'),
|
|
32
|
+
connection: {
|
|
33
|
+
/*...*/
|
|
34
|
+
},
|
|
35
|
+
fetchAsString: ['number', 'clob'],
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 自增列插入
|
|
40
|
+
**knex(tableName, options={identityInsert: boolean})**
|
|
41
|
+
**identityInsert**: 是否开启自增列插入。由于达梦数据库不支持往自增列中手动插入值,此选项通过在插入语句前添加`set identity_insert <table> on;`语句以实现手动插入自增列的功能。
|
|
42
|
+
```js
|
|
43
|
+
knex('test').insert({id: 1}) // 报错:[-2723] 仅当指定列列表,且SET IDENTITY_INSERT为ON时,才能对自增列赋值
|
|
44
|
+
knex('test', {identityInsert: true}).insert({id: 1}) // 执行成功
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Change Logs
|
|
48
|
+
|
|
49
|
+
### knex-dm v1.0.34946(2025-04-07)
|
|
50
|
+
- 发布正式版,已跑通knex源码测例,主要以兼容ORACLE为主
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "knex-dm",
|
|
3
|
+
"version": "1.0.34946",
|
|
4
|
+
"description": "DM database dialect for knex.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "Dameng Database",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"dmdb": "^1.0.34946",
|
|
12
|
+
"lodash": "^4.17.21"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"knex": "^3.1.0"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=16"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// DM Client
|
|
2
|
+
// -------
|
|
3
|
+
const each = require('lodash/each');
|
|
4
|
+
const flatten = require('lodash/flatten');
|
|
5
|
+
const isEmpty = require('lodash/isEmpty');
|
|
6
|
+
const map = require('lodash/map');
|
|
7
|
+
const Client = require('knex/lib/client');
|
|
8
|
+
const Formatter = require('knex/lib/formatter');
|
|
9
|
+
const { isString } = require('knex/lib/util/is');
|
|
10
|
+
const { outputQuery, unwrapRaw } = require('knex/lib/formatter/wrappingFormatter');
|
|
11
|
+
const { compileCallback } = require('knex/lib/formatter/formatterUtils');
|
|
12
|
+
|
|
13
|
+
const QueryBuilder = require('./query/dmdb-querybuilder');
|
|
14
|
+
const QueryCompiler = require('./query/dmdb-querycompiler');
|
|
15
|
+
const SchemaCompiler = require('./schema/dmdb-compiler');
|
|
16
|
+
const TableCompiler = require('./schema/dmdb-tablecompiler');
|
|
17
|
+
const ColumnBuilder = require('./schema/dmdb-columnbuilder');
|
|
18
|
+
const ColumnCompiler = require('./schema/dmdb-columncompiler');
|
|
19
|
+
const {
|
|
20
|
+
BlobHelper,
|
|
21
|
+
ReturningHelper,
|
|
22
|
+
isConnectionError,
|
|
23
|
+
monkeyPatchConnection,
|
|
24
|
+
} = require('./utils');
|
|
25
|
+
const ViewCompiler = require('./schema/dmdb-viewcompiler');
|
|
26
|
+
const ViewBuilder = require('./schema/dmdb-viewbuilder');
|
|
27
|
+
const Transaction = require('./transaction');
|
|
28
|
+
|
|
29
|
+
class Client_DM extends Client {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
super(config);
|
|
32
|
+
|
|
33
|
+
if (this.driver) {
|
|
34
|
+
process.env.UV_THREADPOOL_SIZE = process.env.UV_THREADPOOL_SIZE || 1;
|
|
35
|
+
process.env.UV_THREADPOOL_SIZE =
|
|
36
|
+
parseInt(process.env.UV_THREADPOOL_SIZE) + this.driver.poolMax;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_driver() {
|
|
41
|
+
const client = this;
|
|
42
|
+
const dmdb = require('dmdb');
|
|
43
|
+
client.fetchAsString = [];
|
|
44
|
+
if (this.config.fetchAsString && Array.isArray(this.config.fetchAsString)) {
|
|
45
|
+
this.config.fetchAsString.forEach(function (type) {
|
|
46
|
+
if (!isString(type)) return;
|
|
47
|
+
type = type.toUpperCase();
|
|
48
|
+
if (dmdb[type]) {
|
|
49
|
+
if (
|
|
50
|
+
type !== 'NUMBER' &&
|
|
51
|
+
type !== 'DATE' &&
|
|
52
|
+
type !== 'CLOB' &&
|
|
53
|
+
type !== 'BUFFER'
|
|
54
|
+
) {
|
|
55
|
+
this.logger.warn(
|
|
56
|
+
'Only "date", "number", "clob" and "buffer" are supported for fetchAsString'
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
client.fetchAsString.push(dmdb[type]);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
client.parseJson = this.config.parseJson !== false;
|
|
65
|
+
return dmdb;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
schemaCompiler() {
|
|
69
|
+
return new SchemaCompiler(this, ...arguments);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
queryBuilder() {
|
|
73
|
+
return new QueryBuilder(this);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
queryCompiler(builder, formatter) {
|
|
77
|
+
return new QueryCompiler(this, builder, formatter);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
tableCompiler() {
|
|
81
|
+
return new TableCompiler(this, ...arguments);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
columnBuilder() {
|
|
85
|
+
return new ColumnBuilder(this, ...arguments);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
columnCompiler() {
|
|
89
|
+
return new ColumnCompiler(this, ...arguments);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
viewBuilder() {
|
|
93
|
+
return new ViewBuilder(this, ...arguments);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
viewCompiler() {
|
|
97
|
+
return new ViewCompiler(this, ...arguments);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
formatter(builder) {
|
|
101
|
+
return new Formatter(this, builder);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
transaction() {
|
|
105
|
+
return new Transaction(this, ...arguments);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
prepBindings(bindings) {
|
|
109
|
+
return map(bindings, (value) => {
|
|
110
|
+
if (value instanceof BlobHelper && this.driver) {
|
|
111
|
+
return { type: this.driver.BLOB, dir: this.driver.BIND_OUT };
|
|
112
|
+
// Returning helper always use ROWID as string
|
|
113
|
+
} else if (value instanceof ReturningHelper && this.driver) {
|
|
114
|
+
return { type: this.driver.STRING, dir: this.driver.BIND_OUT };
|
|
115
|
+
} else if (typeof value === 'boolean') {
|
|
116
|
+
return value ? 1 : 0;
|
|
117
|
+
}
|
|
118
|
+
return value;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Checks whether a value is a function... if it is, we compile it
|
|
123
|
+
// otherwise we check whether it's a raw
|
|
124
|
+
parameter(value, builder, formatter) {
|
|
125
|
+
if (typeof value === 'function') {
|
|
126
|
+
return outputQuery(
|
|
127
|
+
compileCallback(value, undefined, this, formatter),
|
|
128
|
+
true,
|
|
129
|
+
builder,
|
|
130
|
+
this
|
|
131
|
+
);
|
|
132
|
+
} else if (value instanceof BlobHelper) {
|
|
133
|
+
formatter.bindings.push(value.value);
|
|
134
|
+
return '?';
|
|
135
|
+
}
|
|
136
|
+
return unwrapRaw(value, true, builder, this, formatter) || '?';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Position the bindings for the query.
|
|
140
|
+
positionBindings(sql) {
|
|
141
|
+
let questionCount = 0;
|
|
142
|
+
return sql.replace(/\?/g, function () {
|
|
143
|
+
questionCount += 1;
|
|
144
|
+
return `:${questionCount}`;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_stream(connection, obj, stream, options) {
|
|
149
|
+
if (!obj.sql) throw new Error('The query is empty');
|
|
150
|
+
|
|
151
|
+
return new Promise(function (resolver, rejecter) {
|
|
152
|
+
stream.on('error', (err) => {
|
|
153
|
+
if (isConnectionError(err)) {
|
|
154
|
+
connection.__knex__disposed = err;
|
|
155
|
+
}
|
|
156
|
+
rejecter(err);
|
|
157
|
+
});
|
|
158
|
+
stream.on('end', resolver);
|
|
159
|
+
const queryStream = connection.queryStream(
|
|
160
|
+
obj.sql,
|
|
161
|
+
obj.bindings,
|
|
162
|
+
options
|
|
163
|
+
);
|
|
164
|
+
queryStream.pipe(stream);
|
|
165
|
+
queryStream.on('error', function (error) {
|
|
166
|
+
rejecter(error);
|
|
167
|
+
stream.emit('error', error);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
alias(first, second) {
|
|
173
|
+
return first + ' ' + second;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Get a raw connection, called by the `pool` whenever a new
|
|
177
|
+
// connection needs to be added to the pool.
|
|
178
|
+
acquireRawConnection() {
|
|
179
|
+
return new Promise((resolver, rejecter) => {
|
|
180
|
+
this.driver.fetchAsString = this.fetchAsString;
|
|
181
|
+
this.driver.parseJson = this.parseJson;
|
|
182
|
+
|
|
183
|
+
this.driver.getConnection(this.connectionSettings, (err, connection) => {
|
|
184
|
+
if (err) {
|
|
185
|
+
return rejecter(err);
|
|
186
|
+
}
|
|
187
|
+
monkeyPatchConnection(connection, this);
|
|
188
|
+
|
|
189
|
+
resolver(connection);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Used to explicitly close a connection, called internally by the pool
|
|
195
|
+
// when a connection times out or the pool is shutdown.
|
|
196
|
+
destroyRawConnection(connection) {
|
|
197
|
+
return connection.release();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Runs the query on the specified connection, providing the bindings
|
|
201
|
+
// and any other necessary prep work.
|
|
202
|
+
_query(connection, obj) {
|
|
203
|
+
if (!obj.sql) throw new Error('The query is empty');
|
|
204
|
+
|
|
205
|
+
const options = Object.assign({}, obj.options, { autoCommit: false });
|
|
206
|
+
if (obj.method === 'select') {
|
|
207
|
+
options.resultSet = true;
|
|
208
|
+
}
|
|
209
|
+
return connection
|
|
210
|
+
.executeAsync(obj.sql, obj.bindings, options)
|
|
211
|
+
.then(async function (response) {
|
|
212
|
+
// Flatten outBinds
|
|
213
|
+
let outBinds = flatten(response.outBinds);
|
|
214
|
+
obj.response = response.rows || [];
|
|
215
|
+
obj.rowsAffected = response.rows
|
|
216
|
+
? response.rows.rowsAffected
|
|
217
|
+
: response.rowsAffected;
|
|
218
|
+
|
|
219
|
+
//added for outBind parameter
|
|
220
|
+
if (obj.method === 'raw' && outBinds.length > 0) {
|
|
221
|
+
return {
|
|
222
|
+
response: outBinds,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (obj.method === 'update') {
|
|
227
|
+
const modifiedRowsCount = obj.rowsAffected.length || obj.rowsAffected;
|
|
228
|
+
const updatedObjOutBinding = [];
|
|
229
|
+
const updatedOutBinds = [];
|
|
230
|
+
const updateOutBinds = (i) =>
|
|
231
|
+
function (value, index) {
|
|
232
|
+
const OutBindsOffset = index * modifiedRowsCount;
|
|
233
|
+
updatedOutBinds.push(outBinds[i + OutBindsOffset]);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
for (let i = 0; i < modifiedRowsCount; i++) {
|
|
237
|
+
updatedObjOutBinding.push(obj.outBinding[0]);
|
|
238
|
+
each(obj.outBinding[0], updateOutBinds(i));
|
|
239
|
+
}
|
|
240
|
+
outBinds = updatedOutBinds;
|
|
241
|
+
obj.outBinding = updatedObjOutBinding;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!obj.returning && outBinds.length === 0) {
|
|
245
|
+
if (!connection.isTransaction) {
|
|
246
|
+
await connection.commitAsync();
|
|
247
|
+
}
|
|
248
|
+
return obj;
|
|
249
|
+
}
|
|
250
|
+
const rowIds = [];
|
|
251
|
+
let offset = 0;
|
|
252
|
+
|
|
253
|
+
for (let line = 0; line < obj.outBinding.length; line++) {
|
|
254
|
+
const ret = obj.outBinding[line];
|
|
255
|
+
|
|
256
|
+
offset =
|
|
257
|
+
offset +
|
|
258
|
+
(obj.outBinding[line - 1] ? obj.outBinding[line - 1].length : 0);
|
|
259
|
+
|
|
260
|
+
for (let index = 0; index < ret.length; index++) {
|
|
261
|
+
const out = ret[index];
|
|
262
|
+
|
|
263
|
+
await new Promise(function (bindResolver, bindRejecter) {
|
|
264
|
+
if (out instanceof BlobHelper) {
|
|
265
|
+
const blob = outBinds[index + offset];
|
|
266
|
+
if (out.returning) {
|
|
267
|
+
obj.response[line] = obj.response[line] || {};
|
|
268
|
+
obj.response[line][out.columnName] = out.value;
|
|
269
|
+
}
|
|
270
|
+
blob.on('error', function (err) {
|
|
271
|
+
bindRejecter(err);
|
|
272
|
+
});
|
|
273
|
+
blob.on('finish', function () {
|
|
274
|
+
bindResolver();
|
|
275
|
+
});
|
|
276
|
+
blob.write(out.value);
|
|
277
|
+
blob.end();
|
|
278
|
+
} else if (obj.outBinding[line][index] === 'ROWID') {
|
|
279
|
+
rowIds.push(outBinds[index + offset]);
|
|
280
|
+
bindResolver();
|
|
281
|
+
} else {
|
|
282
|
+
obj.response[line] = obj.response[line] || {};
|
|
283
|
+
obj.response[line][out] = outBinds[index + offset];
|
|
284
|
+
bindResolver();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (obj.returningSql) {
|
|
290
|
+
const response = await connection.executeAsync(
|
|
291
|
+
obj.returningSql(),
|
|
292
|
+
rowIds,
|
|
293
|
+
{ resultSet: true }
|
|
294
|
+
);
|
|
295
|
+
obj.response = response.rows;
|
|
296
|
+
}
|
|
297
|
+
if (connection.isTransaction) {
|
|
298
|
+
return obj;
|
|
299
|
+
}
|
|
300
|
+
await connection.commitAsync();
|
|
301
|
+
return obj;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Process the response as returned from the query.
|
|
306
|
+
processResponse(obj, runner) {
|
|
307
|
+
const { response } = obj;
|
|
308
|
+
if (obj.output) {
|
|
309
|
+
return obj.output.call(runner, response);
|
|
310
|
+
}
|
|
311
|
+
switch (obj.method) {
|
|
312
|
+
case 'select':
|
|
313
|
+
return response;
|
|
314
|
+
case 'first':
|
|
315
|
+
return response[0];
|
|
316
|
+
case 'pluck':
|
|
317
|
+
return map(response, obj.pluck);
|
|
318
|
+
case 'insert':
|
|
319
|
+
case 'del':
|
|
320
|
+
case 'update':
|
|
321
|
+
case 'counter':
|
|
322
|
+
if ((obj.returning && !isEmpty(obj.returning)) || obj.returningSql) {
|
|
323
|
+
return response;
|
|
324
|
+
} else if (obj.rowsAffected !== undefined) {
|
|
325
|
+
return obj.rowsAffected;
|
|
326
|
+
} else {
|
|
327
|
+
return 1;
|
|
328
|
+
}
|
|
329
|
+
default:
|
|
330
|
+
return response;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
processPassedConnection(connection) {
|
|
335
|
+
monkeyPatchConnection(connection, this);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function resolveConnectString(connectionSettings) {
|
|
340
|
+
if (connectionSettings.connectString) {
|
|
341
|
+
return connectionSettings.connectString;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (!connectionSettings.port) {
|
|
345
|
+
return connectionSettings.host + '/' + connectionSettings.database;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return (
|
|
349
|
+
connectionSettings.host +
|
|
350
|
+
':' +
|
|
351
|
+
connectionSettings.port +
|
|
352
|
+
'/' +
|
|
353
|
+
connectionSettings.database
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
Client_DM.prototype.dialect = 'dmdb';
|
|
358
|
+
Client_DM.prototype.driverName = 'dmdb';
|
|
359
|
+
|
|
360
|
+
module.exports = Client_DM;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const QueryBuilder = require('knex/lib/query/querybuilder');
|
|
2
|
+
|
|
3
|
+
class QueryBuilder_DM extends QueryBuilder {
|
|
4
|
+
// Sets the `tableName` on the query.
|
|
5
|
+
// Alias to "from" for select and "into" for insert statements
|
|
6
|
+
// e.g. builder.insert({a: value}).into('tableName')
|
|
7
|
+
// `options`: options object containing keys:
|
|
8
|
+
// - `only`: whether the query should use SQL's ONLY to not return
|
|
9
|
+
// inheriting table data. Defaults to false.
|
|
10
|
+
// - `identityInsert`: 是否开启自增列插入,自动在insert语句前添加
|
|
11
|
+
// set IDENTITY_INSERT <tableName> on ;
|
|
12
|
+
table(tableName, options = {}) {
|
|
13
|
+
this._single.table = tableName;
|
|
14
|
+
this._single.only = options.only === true;
|
|
15
|
+
this._single.identityInsert = options.identityInsert === true;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = QueryBuilder_DM
|