@faasjs/knex 2.3.1 → 2.5.0
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.js +14 -28
- package/dist/index.mjs +14 -28
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -13,8 +13,7 @@ var knex__default = /*#__PURE__*/_interopDefault(knex);
|
|
|
13
13
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
14
14
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
15
15
|
}) : x)(function(x) {
|
|
16
|
-
if (typeof require !== "undefined")
|
|
17
|
-
return require.apply(this, arguments);
|
|
16
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
18
17
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
19
18
|
});
|
|
20
19
|
var originKnex = knex__default.default;
|
|
@@ -36,13 +35,10 @@ var Knex = class {
|
|
|
36
35
|
}
|
|
37
36
|
async onDeploy(data, next) {
|
|
38
37
|
const client = data.config.plugins[this.name].config.client;
|
|
39
|
-
if (!client)
|
|
40
|
-
throw Error("[Knex] client required.");
|
|
38
|
+
if (!client) throw Error("[Knex] client required.");
|
|
41
39
|
data.dependencies["@faasjs/knex"] = "*";
|
|
42
|
-
if (client === "sqlite3")
|
|
43
|
-
|
|
44
|
-
else
|
|
45
|
-
data.dependencies[client] = "*";
|
|
40
|
+
if (client === "sqlite3") data.dependencies["better-sqlite3"] = "*";
|
|
41
|
+
else data.dependencies[client] = "*";
|
|
46
42
|
new logger.Logger(this.name).debug(`add dependencies: ${client}`);
|
|
47
43
|
await next();
|
|
48
44
|
}
|
|
@@ -68,8 +64,7 @@ var Knex = class {
|
|
|
68
64
|
this.config.connection = /* @__PURE__ */ Object.create(null);
|
|
69
65
|
}
|
|
70
66
|
this.config.connection[key.replace("connection_", "")] = value;
|
|
71
|
-
} else
|
|
72
|
-
this.config[key] = value;
|
|
67
|
+
} else this.config[key] = value;
|
|
73
68
|
}
|
|
74
69
|
if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
|
|
75
70
|
this.config = deep_merge.deepMerge(
|
|
@@ -81,8 +76,7 @@ var Knex = class {
|
|
|
81
76
|
this.config.useNullAsDefault = true;
|
|
82
77
|
}
|
|
83
78
|
if (this.config.client === "pg") {
|
|
84
|
-
if (!this.config.pool)
|
|
85
|
-
this.config.pool = /* @__PURE__ */ Object.create(null);
|
|
79
|
+
if (!this.config.pool) this.config.pool = /* @__PURE__ */ Object.create(null);
|
|
86
80
|
this.config.pool = Object.assign(
|
|
87
81
|
{
|
|
88
82
|
propagateCreateError: false,
|
|
@@ -112,8 +106,7 @@ var Knex = class {
|
|
|
112
106
|
}
|
|
113
107
|
this.query = this.adapter;
|
|
114
108
|
this.query.on("query", ({ sql, __knexQueryUid, bindings }) => {
|
|
115
|
-
if (!__knexQueryUid)
|
|
116
|
-
return;
|
|
109
|
+
if (!__knexQueryUid) return;
|
|
117
110
|
this.logger.time(`Knex${this.name}${__knexQueryUid}`);
|
|
118
111
|
this.logger.debug(
|
|
119
112
|
"[%s] [%s] query begin: %s %j",
|
|
@@ -123,8 +116,7 @@ var Knex = class {
|
|
|
123
116
|
bindings
|
|
124
117
|
);
|
|
125
118
|
}).on("query-response", (response, { sql, __knexQueryUid, bindings }) => {
|
|
126
|
-
if (!__knexQueryUid)
|
|
127
|
-
return;
|
|
119
|
+
if (!__knexQueryUid) return;
|
|
128
120
|
this.logger.timeEnd(
|
|
129
121
|
`Knex${this.name}${__knexQueryUid}`,
|
|
130
122
|
"[%s] [%s] query done: %s %j %j",
|
|
@@ -135,8 +127,7 @@ var Knex = class {
|
|
|
135
127
|
response
|
|
136
128
|
);
|
|
137
129
|
}).on("query-error", (_, { __knexQueryUid, sql, bindings }) => {
|
|
138
|
-
if (!__knexQueryUid)
|
|
139
|
-
return;
|
|
130
|
+
if (!__knexQueryUid) return;
|
|
140
131
|
this.logger.timeEnd(
|
|
141
132
|
`Knex${this.name}${__knexQueryUid}`,
|
|
142
133
|
"[%s] [%s] query failed: %s %j",
|
|
@@ -155,8 +146,7 @@ var Knex = class {
|
|
|
155
146
|
await next();
|
|
156
147
|
}
|
|
157
148
|
async raw(sql, bindings = []) {
|
|
158
|
-
if (!this.adapter)
|
|
159
|
-
throw Error("[Knex] Client not initialized.");
|
|
149
|
+
if (!this.adapter) throw Error("[Knex] Client not initialized.");
|
|
160
150
|
return this.adapter.raw(sql, bindings);
|
|
161
151
|
}
|
|
162
152
|
/**
|
|
@@ -165,10 +155,8 @@ var Knex = class {
|
|
|
165
155
|
* - Support 'commit' and 'rollback' event.
|
|
166
156
|
*/
|
|
167
157
|
async transaction(scope, config, options) {
|
|
168
|
-
if (!this.adapter)
|
|
169
|
-
|
|
170
|
-
if (options == null ? void 0 : options.trx)
|
|
171
|
-
return scope(options.trx);
|
|
158
|
+
if (!this.adapter) throw Error(`[${this.name}] Client not initialized.`);
|
|
159
|
+
if (options == null ? void 0 : options.trx) return scope(options.trx);
|
|
172
160
|
const trx = await this.adapter.transaction(config);
|
|
173
161
|
const trxId = crypto.randomUUID();
|
|
174
162
|
this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
|
|
@@ -205,8 +193,7 @@ var Knex = class {
|
|
|
205
193
|
}
|
|
206
194
|
}
|
|
207
195
|
schema() {
|
|
208
|
-
if (!this.adapter)
|
|
209
|
-
throw Error(`[${this.name}] Client not initialized.`);
|
|
196
|
+
if (!this.adapter) throw Error(`[${this.name}] Client not initialized.`);
|
|
210
197
|
return this.adapter.schema;
|
|
211
198
|
}
|
|
212
199
|
async quit() {
|
|
@@ -220,8 +207,7 @@ var Knex = class {
|
|
|
220
207
|
};
|
|
221
208
|
function useKnex(config) {
|
|
222
209
|
const name = (config == null ? void 0 : config.name) || Name;
|
|
223
|
-
if (global.FaasJS_Knex[name])
|
|
224
|
-
return func.usePlugin(global.FaasJS_Knex[name]);
|
|
210
|
+
if (global.FaasJS_Knex[name]) return func.usePlugin(global.FaasJS_Knex[name]);
|
|
225
211
|
return func.usePlugin(new Knex(config));
|
|
226
212
|
}
|
|
227
213
|
function query(table) {
|
package/dist/index.mjs
CHANGED
|
@@ -7,8 +7,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
7
7
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
8
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
9
|
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined")
|
|
11
|
-
return require.apply(this, arguments);
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
12
|
});
|
|
14
13
|
var originKnex = knex;
|
|
@@ -30,13 +29,10 @@ var Knex = class {
|
|
|
30
29
|
}
|
|
31
30
|
async onDeploy(data, next) {
|
|
32
31
|
const client = data.config.plugins[this.name].config.client;
|
|
33
|
-
if (!client)
|
|
34
|
-
throw Error("[Knex] client required.");
|
|
32
|
+
if (!client) throw Error("[Knex] client required.");
|
|
35
33
|
data.dependencies["@faasjs/knex"] = "*";
|
|
36
|
-
if (client === "sqlite3")
|
|
37
|
-
|
|
38
|
-
else
|
|
39
|
-
data.dependencies[client] = "*";
|
|
34
|
+
if (client === "sqlite3") data.dependencies["better-sqlite3"] = "*";
|
|
35
|
+
else data.dependencies[client] = "*";
|
|
40
36
|
new Logger(this.name).debug(`add dependencies: ${client}`);
|
|
41
37
|
await next();
|
|
42
38
|
}
|
|
@@ -62,8 +58,7 @@ var Knex = class {
|
|
|
62
58
|
this.config.connection = /* @__PURE__ */ Object.create(null);
|
|
63
59
|
}
|
|
64
60
|
this.config.connection[key.replace("connection_", "")] = value;
|
|
65
|
-
} else
|
|
66
|
-
this.config[key] = value;
|
|
61
|
+
} else this.config[key] = value;
|
|
67
62
|
}
|
|
68
63
|
if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
|
|
69
64
|
this.config = deepMerge(
|
|
@@ -75,8 +70,7 @@ var Knex = class {
|
|
|
75
70
|
this.config.useNullAsDefault = true;
|
|
76
71
|
}
|
|
77
72
|
if (this.config.client === "pg") {
|
|
78
|
-
if (!this.config.pool)
|
|
79
|
-
this.config.pool = /* @__PURE__ */ Object.create(null);
|
|
73
|
+
if (!this.config.pool) this.config.pool = /* @__PURE__ */ Object.create(null);
|
|
80
74
|
this.config.pool = Object.assign(
|
|
81
75
|
{
|
|
82
76
|
propagateCreateError: false,
|
|
@@ -106,8 +100,7 @@ var Knex = class {
|
|
|
106
100
|
}
|
|
107
101
|
this.query = this.adapter;
|
|
108
102
|
this.query.on("query", ({ sql, __knexQueryUid, bindings }) => {
|
|
109
|
-
if (!__knexQueryUid)
|
|
110
|
-
return;
|
|
103
|
+
if (!__knexQueryUid) return;
|
|
111
104
|
this.logger.time(`Knex${this.name}${__knexQueryUid}`);
|
|
112
105
|
this.logger.debug(
|
|
113
106
|
"[%s] [%s] query begin: %s %j",
|
|
@@ -117,8 +110,7 @@ var Knex = class {
|
|
|
117
110
|
bindings
|
|
118
111
|
);
|
|
119
112
|
}).on("query-response", (response, { sql, __knexQueryUid, bindings }) => {
|
|
120
|
-
if (!__knexQueryUid)
|
|
121
|
-
return;
|
|
113
|
+
if (!__knexQueryUid) return;
|
|
122
114
|
this.logger.timeEnd(
|
|
123
115
|
`Knex${this.name}${__knexQueryUid}`,
|
|
124
116
|
"[%s] [%s] query done: %s %j %j",
|
|
@@ -129,8 +121,7 @@ var Knex = class {
|
|
|
129
121
|
response
|
|
130
122
|
);
|
|
131
123
|
}).on("query-error", (_, { __knexQueryUid, sql, bindings }) => {
|
|
132
|
-
if (!__knexQueryUid)
|
|
133
|
-
return;
|
|
124
|
+
if (!__knexQueryUid) return;
|
|
134
125
|
this.logger.timeEnd(
|
|
135
126
|
`Knex${this.name}${__knexQueryUid}`,
|
|
136
127
|
"[%s] [%s] query failed: %s %j",
|
|
@@ -149,8 +140,7 @@ var Knex = class {
|
|
|
149
140
|
await next();
|
|
150
141
|
}
|
|
151
142
|
async raw(sql, bindings = []) {
|
|
152
|
-
if (!this.adapter)
|
|
153
|
-
throw Error("[Knex] Client not initialized.");
|
|
143
|
+
if (!this.adapter) throw Error("[Knex] Client not initialized.");
|
|
154
144
|
return this.adapter.raw(sql, bindings);
|
|
155
145
|
}
|
|
156
146
|
/**
|
|
@@ -159,10 +149,8 @@ var Knex = class {
|
|
|
159
149
|
* - Support 'commit' and 'rollback' event.
|
|
160
150
|
*/
|
|
161
151
|
async transaction(scope, config, options) {
|
|
162
|
-
if (!this.adapter)
|
|
163
|
-
|
|
164
|
-
if (options == null ? void 0 : options.trx)
|
|
165
|
-
return scope(options.trx);
|
|
152
|
+
if (!this.adapter) throw Error(`[${this.name}] Client not initialized.`);
|
|
153
|
+
if (options == null ? void 0 : options.trx) return scope(options.trx);
|
|
166
154
|
const trx = await this.adapter.transaction(config);
|
|
167
155
|
const trxId = randomUUID();
|
|
168
156
|
this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
|
|
@@ -199,8 +187,7 @@ var Knex = class {
|
|
|
199
187
|
}
|
|
200
188
|
}
|
|
201
189
|
schema() {
|
|
202
|
-
if (!this.adapter)
|
|
203
|
-
throw Error(`[${this.name}] Client not initialized.`);
|
|
190
|
+
if (!this.adapter) throw Error(`[${this.name}] Client not initialized.`);
|
|
204
191
|
return this.adapter.schema;
|
|
205
192
|
}
|
|
206
193
|
async quit() {
|
|
@@ -214,8 +201,7 @@ var Knex = class {
|
|
|
214
201
|
};
|
|
215
202
|
function useKnex(config) {
|
|
216
203
|
const name = (config == null ? void 0 : config.name) || Name;
|
|
217
|
-
if (global.FaasJS_Knex[name])
|
|
218
|
-
return usePlugin(global.FaasJS_Knex[name]);
|
|
204
|
+
if (global.FaasJS_Knex[name]) return usePlugin(global.FaasJS_Knex[name]);
|
|
219
205
|
return usePlugin(new Knex(config));
|
|
220
206
|
}
|
|
221
207
|
function query(table) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/knex",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@faasjs/deep_merge": "2.
|
|
25
|
-
"@faasjs/func": "2.
|
|
26
|
-
"@faasjs/logger": "2.
|
|
24
|
+
"@faasjs/deep_merge": "2.5.0",
|
|
25
|
+
"@faasjs/func": "2.5.0",
|
|
26
|
+
"@faasjs/logger": "2.5.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"knex": "*"
|