@faasjs/knex 3.1.0 → 3.1.1
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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -31
- package/dist/index.mjs +13 -31
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,12 +16,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
16
16
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
17
|
});
|
|
18
18
|
var originKnex = knex__default.default;
|
|
19
|
-
var Name = "
|
|
19
|
+
var Name = "Knex";
|
|
20
20
|
if (!global.FaasJS_Knex) {
|
|
21
21
|
global.FaasJS_Knex = {};
|
|
22
22
|
}
|
|
23
23
|
var Knex = class {
|
|
24
|
-
type =
|
|
24
|
+
type = "knex";
|
|
25
25
|
name = Name;
|
|
26
26
|
config;
|
|
27
27
|
adapter;
|
|
@@ -29,10 +29,9 @@ var Knex = class {
|
|
|
29
29
|
logger;
|
|
30
30
|
constructor(config) {
|
|
31
31
|
if (config) {
|
|
32
|
-
this.name = config.name || this.
|
|
32
|
+
this.name = config.name || this.name;
|
|
33
33
|
this.config = config.config || /* @__PURE__ */ Object.create(null);
|
|
34
34
|
} else {
|
|
35
|
-
this.name = this.type;
|
|
36
35
|
this.config = /* @__PURE__ */ Object.create(null);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -42,7 +41,7 @@ var Knex = class {
|
|
|
42
41
|
this.config = global.FaasJS_Knex[this.name].config;
|
|
43
42
|
this.adapter = global.FaasJS_Knex[this.name].adapter;
|
|
44
43
|
this.query = this.adapter;
|
|
45
|
-
this.logger.debug("
|
|
44
|
+
this.logger.debug("use exists adapter");
|
|
46
45
|
await next();
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
@@ -123,8 +122,7 @@ var Knex = class {
|
|
|
123
122
|
if (!__knexQueryUid) return;
|
|
124
123
|
this.logger.time(`Knex${this.name}${__knexQueryUid}`);
|
|
125
124
|
this.logger.debug(
|
|
126
|
-
"[%s]
|
|
127
|
-
this.name,
|
|
125
|
+
"[%s] query begin: %s %j",
|
|
128
126
|
__knexQueryUid,
|
|
129
127
|
sql,
|
|
130
128
|
bindings
|
|
@@ -133,8 +131,7 @@ var Knex = class {
|
|
|
133
131
|
if (!__knexQueryUid) return;
|
|
134
132
|
this.logger.timeEnd(
|
|
135
133
|
`Knex${this.name}${__knexQueryUid}`,
|
|
136
|
-
"[%s]
|
|
137
|
-
this.name,
|
|
134
|
+
"[%s] query done: %s %j %j",
|
|
138
135
|
__knexQueryUid,
|
|
139
136
|
sql,
|
|
140
137
|
bindings,
|
|
@@ -144,14 +141,13 @@ var Knex = class {
|
|
|
144
141
|
if (!__knexQueryUid) return;
|
|
145
142
|
this.logger.timeEnd(
|
|
146
143
|
`Knex${this.name}${__knexQueryUid}`,
|
|
147
|
-
"[%s]
|
|
148
|
-
this.name,
|
|
144
|
+
"[%s] query failed: %s %j",
|
|
149
145
|
__knexQueryUid,
|
|
150
146
|
sql,
|
|
151
147
|
bindings
|
|
152
148
|
);
|
|
153
149
|
});
|
|
154
|
-
data.logger.debug("
|
|
150
|
+
data.logger.debug("connected");
|
|
155
151
|
global.FaasJS_Knex[this.name] = this;
|
|
156
152
|
await next();
|
|
157
153
|
}
|
|
@@ -173,35 +169,21 @@ var Knex = class {
|
|
|
173
169
|
if (options?.trx) return scope(options.trx);
|
|
174
170
|
const trx = await this.adapter.transaction(config);
|
|
175
171
|
const trxId = crypto.randomUUID();
|
|
176
|
-
this.logger.debug("[%s]
|
|
172
|
+
this.logger.debug("[%s] transaction begin", trxId);
|
|
177
173
|
try {
|
|
178
174
|
const result = await scope(trx);
|
|
179
175
|
if (trx.isCompleted()) {
|
|
180
|
-
this.logger.debug(
|
|
181
|
-
"[%s] [%s] transaction has been finished in scope",
|
|
182
|
-
this.name,
|
|
183
|
-
trxId
|
|
184
|
-
);
|
|
176
|
+
this.logger.debug("[%s] transaction has been finished in scope", trxId);
|
|
185
177
|
return result;
|
|
186
178
|
}
|
|
187
|
-
this.logger.debug("[%s]
|
|
179
|
+
this.logger.debug("[%s] transaction begin commit", trxId);
|
|
188
180
|
await trx.commit();
|
|
189
|
-
this.logger.debug(
|
|
190
|
-
"[%s] [%s] transaction committed: %j",
|
|
191
|
-
this.name,
|
|
192
|
-
trxId,
|
|
193
|
-
result
|
|
194
|
-
);
|
|
181
|
+
this.logger.debug("[%s] transaction committed: %j", trxId, result);
|
|
195
182
|
trx.emit("commit");
|
|
196
183
|
return result;
|
|
197
184
|
} catch (error) {
|
|
198
185
|
await trx.rollback(error);
|
|
199
|
-
this.logger.error(
|
|
200
|
-
"[%s] [%s] transaction rollback: %s",
|
|
201
|
-
this.name,
|
|
202
|
-
trxId,
|
|
203
|
-
error
|
|
204
|
-
);
|
|
186
|
+
this.logger.error("[%s] transaction rollback: %s", trxId, error);
|
|
205
187
|
trx.emit("rollback", error);
|
|
206
188
|
throw error;
|
|
207
189
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -10,12 +10,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
10
10
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
11
11
|
});
|
|
12
12
|
var originKnex = knex;
|
|
13
|
-
var Name = "
|
|
13
|
+
var Name = "Knex";
|
|
14
14
|
if (!global.FaasJS_Knex) {
|
|
15
15
|
global.FaasJS_Knex = {};
|
|
16
16
|
}
|
|
17
17
|
var Knex = class {
|
|
18
|
-
type =
|
|
18
|
+
type = "knex";
|
|
19
19
|
name = Name;
|
|
20
20
|
config;
|
|
21
21
|
adapter;
|
|
@@ -23,10 +23,9 @@ var Knex = class {
|
|
|
23
23
|
logger;
|
|
24
24
|
constructor(config) {
|
|
25
25
|
if (config) {
|
|
26
|
-
this.name = config.name || this.
|
|
26
|
+
this.name = config.name || this.name;
|
|
27
27
|
this.config = config.config || /* @__PURE__ */ Object.create(null);
|
|
28
28
|
} else {
|
|
29
|
-
this.name = this.type;
|
|
30
29
|
this.config = /* @__PURE__ */ Object.create(null);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -36,7 +35,7 @@ var Knex = class {
|
|
|
36
35
|
this.config = global.FaasJS_Knex[this.name].config;
|
|
37
36
|
this.adapter = global.FaasJS_Knex[this.name].adapter;
|
|
38
37
|
this.query = this.adapter;
|
|
39
|
-
this.logger.debug("
|
|
38
|
+
this.logger.debug("use exists adapter");
|
|
40
39
|
await next();
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
@@ -117,8 +116,7 @@ var Knex = class {
|
|
|
117
116
|
if (!__knexQueryUid) return;
|
|
118
117
|
this.logger.time(`Knex${this.name}${__knexQueryUid}`);
|
|
119
118
|
this.logger.debug(
|
|
120
|
-
"[%s]
|
|
121
|
-
this.name,
|
|
119
|
+
"[%s] query begin: %s %j",
|
|
122
120
|
__knexQueryUid,
|
|
123
121
|
sql,
|
|
124
122
|
bindings
|
|
@@ -127,8 +125,7 @@ var Knex = class {
|
|
|
127
125
|
if (!__knexQueryUid) return;
|
|
128
126
|
this.logger.timeEnd(
|
|
129
127
|
`Knex${this.name}${__knexQueryUid}`,
|
|
130
|
-
"[%s]
|
|
131
|
-
this.name,
|
|
128
|
+
"[%s] query done: %s %j %j",
|
|
132
129
|
__knexQueryUid,
|
|
133
130
|
sql,
|
|
134
131
|
bindings,
|
|
@@ -138,14 +135,13 @@ var Knex = class {
|
|
|
138
135
|
if (!__knexQueryUid) return;
|
|
139
136
|
this.logger.timeEnd(
|
|
140
137
|
`Knex${this.name}${__knexQueryUid}`,
|
|
141
|
-
"[%s]
|
|
142
|
-
this.name,
|
|
138
|
+
"[%s] query failed: %s %j",
|
|
143
139
|
__knexQueryUid,
|
|
144
140
|
sql,
|
|
145
141
|
bindings
|
|
146
142
|
);
|
|
147
143
|
});
|
|
148
|
-
data.logger.debug("
|
|
144
|
+
data.logger.debug("connected");
|
|
149
145
|
global.FaasJS_Knex[this.name] = this;
|
|
150
146
|
await next();
|
|
151
147
|
}
|
|
@@ -167,35 +163,21 @@ var Knex = class {
|
|
|
167
163
|
if (options?.trx) return scope(options.trx);
|
|
168
164
|
const trx = await this.adapter.transaction(config);
|
|
169
165
|
const trxId = randomUUID();
|
|
170
|
-
this.logger.debug("[%s]
|
|
166
|
+
this.logger.debug("[%s] transaction begin", trxId);
|
|
171
167
|
try {
|
|
172
168
|
const result = await scope(trx);
|
|
173
169
|
if (trx.isCompleted()) {
|
|
174
|
-
this.logger.debug(
|
|
175
|
-
"[%s] [%s] transaction has been finished in scope",
|
|
176
|
-
this.name,
|
|
177
|
-
trxId
|
|
178
|
-
);
|
|
170
|
+
this.logger.debug("[%s] transaction has been finished in scope", trxId);
|
|
179
171
|
return result;
|
|
180
172
|
}
|
|
181
|
-
this.logger.debug("[%s]
|
|
173
|
+
this.logger.debug("[%s] transaction begin commit", trxId);
|
|
182
174
|
await trx.commit();
|
|
183
|
-
this.logger.debug(
|
|
184
|
-
"[%s] [%s] transaction committed: %j",
|
|
185
|
-
this.name,
|
|
186
|
-
trxId,
|
|
187
|
-
result
|
|
188
|
-
);
|
|
175
|
+
this.logger.debug("[%s] transaction committed: %j", trxId, result);
|
|
189
176
|
trx.emit("commit");
|
|
190
177
|
return result;
|
|
191
178
|
} catch (error) {
|
|
192
179
|
await trx.rollback(error);
|
|
193
|
-
this.logger.error(
|
|
194
|
-
"[%s] [%s] transaction rollback: %s",
|
|
195
|
-
this.name,
|
|
196
|
-
trxId,
|
|
197
|
-
error
|
|
198
|
-
);
|
|
180
|
+
this.logger.error("[%s] transaction rollback: %s", trxId, error);
|
|
199
181
|
trx.emit("rollback", error);
|
|
200
182
|
throw error;
|
|
201
183
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/knex",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@faasjs/deep_merge": "3.1.
|
|
38
|
-
"@faasjs/func": "3.1.
|
|
39
|
-
"@faasjs/logger": "3.1.
|
|
37
|
+
"@faasjs/deep_merge": "3.1.1",
|
|
38
|
+
"@faasjs/func": "3.1.1",
|
|
39
|
+
"@faasjs/logger": "3.1.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"knex": "*"
|