/
index.js
86 lines (73 loc) · 2.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// CockroachDB Client
// -------
const Client_PostgreSQL = require('../postgres');
const Transaction = require('../postgres/execution/pg-transaction');
const QueryCompiler = require('./crdb-querycompiler');
const ColumnCompiler = require('./crdb-columncompiler');
const TableCompiler = require('./crdb-tablecompiler');
const ViewCompiler = require('./crdb-viewcompiler');
const QueryBuilder = require('./crdb-querybuilder');
// Always initialize with the "QueryBuilder" and "QueryCompiler"
// objects, which extend the base 'lib/query/builder' and
// 'lib/query/compiler', respectively.
class Client_CockroachDB extends Client_PostgreSQL {
transaction() {
return new Transaction(this, ...arguments);
}
queryCompiler(builder, formatter) {
return new QueryCompiler(this, builder, formatter);
}
columnCompiler() {
return new ColumnCompiler(this, ...arguments);
}
tableCompiler() {
return new TableCompiler(this, ...arguments);
}
viewCompiler() {
return new ViewCompiler(this, ...arguments);
}
queryBuilder() {
return new QueryBuilder(this);
}
_parseVersion(versionString) {
return versionString.split(' ')[2];
}
async cancelQuery(connectionToKill) {
try {
return await this._wrappedCancelQueryCall(null, connectionToKill);
} catch (err) {
this.logger.warn(`Connection Error: ${err}`);
throw err;
}
}
_wrappedCancelQueryCall(emptyConnection, connectionToKill) {
// FixMe https://github.com/cockroachdb/cockroach/issues/41335
if (
connectionToKill.activeQuery.processID === 0 &&
connectionToKill.activeQuery.secretKey === 0
) {
return;
}
return connectionToKill.cancel(
connectionToKill,
connectionToKill.activeQuery
);
}
toArrayPathFromJsonPath(jsonPath, builder, bindingsHolder) {
return jsonPath
.replace(/^(\$\.)/, '') // remove the first dollar
.replace(/\[([0-9]+)]/, '.$1')
.split('.')
.map(
function (v) {
return this.parameter(v, builder, bindingsHolder);
}.bind(this)
)
.join(', ');
}
}
Object.assign(Client_CockroachDB.prototype, {
// The "dialect", for reference elsewhere.
driverName: 'cockroachdb',
});
module.exports = Client_CockroachDB;