@faasjs/knex 0.0.2-beta.398 → 0.0.2-beta.401
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.ts +3 -3
- package/dist/index.js +13 -10
- package/dist/index.mjs +13 -10
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Plugin, DeployData, Next, MountData, UseifyPlugin } from '@faasjs/func';
|
|
2
|
-
import { Logger } from '@faasjs/logger';
|
|
1
|
+
import { Plugin, DeployData, Next, MountData, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
3
2
|
import { Knex as Knex$1 } from 'knex';
|
|
4
3
|
|
|
5
4
|
declare type KnexConfig = {
|
|
@@ -15,7 +14,7 @@ declare class Knex implements Plugin {
|
|
|
15
14
|
config: Knex$1.Config;
|
|
16
15
|
adapter: Knex$1;
|
|
17
16
|
query: Knex$1;
|
|
18
|
-
logger
|
|
17
|
+
private logger;
|
|
19
18
|
/**
|
|
20
19
|
* 创建插件实例
|
|
21
20
|
* @param config {object} 配置
|
|
@@ -25,6 +24,7 @@ declare class Knex implements Plugin {
|
|
|
25
24
|
constructor(config?: KnexConfig);
|
|
26
25
|
onDeploy(data: DeployData, next: Next): Promise<void>;
|
|
27
26
|
onMount(data: MountData, next: Next): Promise<void>;
|
|
27
|
+
onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
|
|
28
28
|
raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
|
|
29
29
|
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: any): Promise<TResult>;
|
|
30
30
|
schema(): Knex$1.SchemaBuilder;
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,6 @@ var Knex = class {
|
|
|
52
52
|
this.name = this.type;
|
|
53
53
|
this.config = /* @__PURE__ */ Object.create(null);
|
|
54
54
|
}
|
|
55
|
-
this.logger = new import_logger.Logger(this.name);
|
|
56
55
|
}
|
|
57
56
|
async onDeploy(data, next) {
|
|
58
57
|
const client = data.config.plugins[this.name].config.client;
|
|
@@ -63,7 +62,7 @@ var Knex = class {
|
|
|
63
62
|
data.dependencies["better-sqlite3"] = "*";
|
|
64
63
|
else
|
|
65
64
|
data.dependencies[client] = "*";
|
|
66
|
-
this.
|
|
65
|
+
new import_logger.Logger(this.name).debug("add dependencies: " + client);
|
|
67
66
|
await next();
|
|
68
67
|
}
|
|
69
68
|
async onMount(data, next) {
|
|
@@ -115,31 +114,35 @@ var Knex = class {
|
|
|
115
114
|
(v) => parseFloat(v)
|
|
116
115
|
));
|
|
117
116
|
}
|
|
118
|
-
this.
|
|
117
|
+
this.query = this.adapter;
|
|
118
|
+
this.query.on("query", ({
|
|
119
119
|
sql,
|
|
120
120
|
__knexQueryUid,
|
|
121
121
|
bindings
|
|
122
122
|
}) => {
|
|
123
123
|
this.logger.time(`Knex${__knexQueryUid}`);
|
|
124
|
-
this.logger.debug("query begin: %s %j", sql, bindings);
|
|
124
|
+
this.logger.debug("[%s] query begin: %s %j", this.name, sql, bindings);
|
|
125
125
|
}).on("query-response", (response, {
|
|
126
126
|
sql,
|
|
127
127
|
__knexQueryUid,
|
|
128
128
|
bindings
|
|
129
129
|
}) => {
|
|
130
|
-
this.logger.timeEnd(`Knex${__knexQueryUid}`, "query done: %s %j %j", sql, bindings, response);
|
|
130
|
+
this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query done: %s %j %j", this.name, sql, bindings, response);
|
|
131
131
|
}).on("query-error", (_, {
|
|
132
132
|
__knexQueryUid,
|
|
133
133
|
sql,
|
|
134
134
|
bindings
|
|
135
135
|
}) => {
|
|
136
|
-
this.logger.timeEnd(`Knex${__knexQueryUid}`, "query failed: %s %j", sql, bindings);
|
|
136
|
+
this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query failed: %s %j", this.name, sql, bindings);
|
|
137
137
|
});
|
|
138
|
-
|
|
139
|
-
this.logger.debug("connected");
|
|
138
|
+
data.logger.debug("[%s] connected", this.name);
|
|
140
139
|
global.FaasJS_Knex[this.name] = this;
|
|
141
140
|
await next();
|
|
142
141
|
}
|
|
142
|
+
async onInvoke(data, next) {
|
|
143
|
+
this.logger = data.logger;
|
|
144
|
+
await next();
|
|
145
|
+
}
|
|
143
146
|
async raw(sql, bindings = []) {
|
|
144
147
|
if (!this.adapter)
|
|
145
148
|
throw Error("[Knex] Client not initialized.");
|
|
@@ -147,12 +150,12 @@ var Knex = class {
|
|
|
147
150
|
}
|
|
148
151
|
async transaction(scope, config) {
|
|
149
152
|
if (!this.adapter)
|
|
150
|
-
throw Error(
|
|
153
|
+
throw Error(`[${this.name}] Client not initialized.`);
|
|
151
154
|
return this.adapter.transaction(scope, config);
|
|
152
155
|
}
|
|
153
156
|
schema() {
|
|
154
157
|
if (!this.adapter)
|
|
155
|
-
throw Error(
|
|
158
|
+
throw Error(`[${this.name}] Client not initialized.`);
|
|
156
159
|
return this.adapter.schema;
|
|
157
160
|
}
|
|
158
161
|
async quit() {
|
package/dist/index.mjs
CHANGED
|
@@ -28,7 +28,6 @@ var Knex = class {
|
|
|
28
28
|
this.name = this.type;
|
|
29
29
|
this.config = /* @__PURE__ */ Object.create(null);
|
|
30
30
|
}
|
|
31
|
-
this.logger = new Logger(this.name);
|
|
32
31
|
}
|
|
33
32
|
async onDeploy(data, next) {
|
|
34
33
|
const client = data.config.plugins[this.name].config.client;
|
|
@@ -39,7 +38,7 @@ var Knex = class {
|
|
|
39
38
|
data.dependencies["better-sqlite3"] = "*";
|
|
40
39
|
else
|
|
41
40
|
data.dependencies[client] = "*";
|
|
42
|
-
this.
|
|
41
|
+
new Logger(this.name).debug("add dependencies: " + client);
|
|
43
42
|
await next();
|
|
44
43
|
}
|
|
45
44
|
async onMount(data, next) {
|
|
@@ -91,31 +90,35 @@ var Knex = class {
|
|
|
91
90
|
(v) => parseFloat(v)
|
|
92
91
|
));
|
|
93
92
|
}
|
|
94
|
-
this.
|
|
93
|
+
this.query = this.adapter;
|
|
94
|
+
this.query.on("query", ({
|
|
95
95
|
sql,
|
|
96
96
|
__knexQueryUid,
|
|
97
97
|
bindings
|
|
98
98
|
}) => {
|
|
99
99
|
this.logger.time(`Knex${__knexQueryUid}`);
|
|
100
|
-
this.logger.debug("query begin: %s %j", sql, bindings);
|
|
100
|
+
this.logger.debug("[%s] query begin: %s %j", this.name, sql, bindings);
|
|
101
101
|
}).on("query-response", (response, {
|
|
102
102
|
sql,
|
|
103
103
|
__knexQueryUid,
|
|
104
104
|
bindings
|
|
105
105
|
}) => {
|
|
106
|
-
this.logger.timeEnd(`Knex${__knexQueryUid}`, "query done: %s %j %j", sql, bindings, response);
|
|
106
|
+
this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query done: %s %j %j", this.name, sql, bindings, response);
|
|
107
107
|
}).on("query-error", (_, {
|
|
108
108
|
__knexQueryUid,
|
|
109
109
|
sql,
|
|
110
110
|
bindings
|
|
111
111
|
}) => {
|
|
112
|
-
this.logger.timeEnd(`Knex${__knexQueryUid}`, "query failed: %s %j", sql, bindings);
|
|
112
|
+
this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query failed: %s %j", this.name, sql, bindings);
|
|
113
113
|
});
|
|
114
|
-
|
|
115
|
-
this.logger.debug("connected");
|
|
114
|
+
data.logger.debug("[%s] connected", this.name);
|
|
116
115
|
global.FaasJS_Knex[this.name] = this;
|
|
117
116
|
await next();
|
|
118
117
|
}
|
|
118
|
+
async onInvoke(data, next) {
|
|
119
|
+
this.logger = data.logger;
|
|
120
|
+
await next();
|
|
121
|
+
}
|
|
119
122
|
async raw(sql, bindings = []) {
|
|
120
123
|
if (!this.adapter)
|
|
121
124
|
throw Error("[Knex] Client not initialized.");
|
|
@@ -123,12 +126,12 @@ var Knex = class {
|
|
|
123
126
|
}
|
|
124
127
|
async transaction(scope, config) {
|
|
125
128
|
if (!this.adapter)
|
|
126
|
-
throw Error(
|
|
129
|
+
throw Error(`[${this.name}] Client not initialized.`);
|
|
127
130
|
return this.adapter.transaction(scope, config);
|
|
128
131
|
}
|
|
129
132
|
schema() {
|
|
130
133
|
if (!this.adapter)
|
|
131
|
-
throw Error(
|
|
134
|
+
throw Error(`[${this.name}] Client not initialized.`);
|
|
132
135
|
return this.adapter.schema;
|
|
133
136
|
}
|
|
134
137
|
async quit() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/knex",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.401",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@faasjs/deep_merge": "^0.0.2-beta.
|
|
26
|
-
"@faasjs/func": "^0.0.2-beta.
|
|
27
|
-
"@faasjs/logger": "^0.0.2-beta.
|
|
25
|
+
"@faasjs/deep_merge": "^0.0.2-beta.401",
|
|
26
|
+
"@faasjs/func": "^0.0.2-beta.401",
|
|
27
|
+
"@faasjs/logger": "^0.0.2-beta.401",
|
|
28
28
|
"knex": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"typescript": "*"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
|
-
"npm": ">=8.0.0"
|
|
41
|
+
"npm": ">=8.0.0",
|
|
42
|
+
"node": ">=16.0.0"
|
|
42
43
|
}
|
|
43
44
|
}
|