@faasjs/knex 0.0.2-beta.233 → 0.0.2-beta.253
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/lib/index.d.ts +1 -1
- package/lib/index.es.js +13 -11
- package/lib/index.js +16 -16
- package/package.json +5 -5
package/lib/index.d.ts
CHANGED
package/lib/index.es.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { usePlugin } from '@faasjs/func';
|
|
2
|
-
import Logger from '@faasjs/logger';
|
|
3
|
-
import deepMerge from '@faasjs/deep_merge';
|
|
2
|
+
import { Logger } from '@faasjs/logger';
|
|
3
|
+
import { deepMerge } from '@faasjs/deep_merge';
|
|
4
4
|
import knex from 'knex';
|
|
5
5
|
|
|
6
6
|
const Name = 'knex';
|
|
7
|
-
|
|
7
|
+
if (!global['FaasJS_Knex']) {
|
|
8
|
+
global.FaasJS_Knex = {};
|
|
9
|
+
}
|
|
8
10
|
/**
|
|
9
11
|
* Knex 插件
|
|
10
12
|
*/
|
|
@@ -38,9 +40,9 @@ class Knex {
|
|
|
38
40
|
}
|
|
39
41
|
async onMount(data, next) {
|
|
40
42
|
var _a;
|
|
41
|
-
if (
|
|
42
|
-
this.config =
|
|
43
|
-
this.adapter =
|
|
43
|
+
if (global.FaasJS_Knex[this.name]) {
|
|
44
|
+
this.config = global.FaasJS_Knex[this.name].config;
|
|
45
|
+
this.adapter = global.FaasJS_Knex[this.name].adapter;
|
|
44
46
|
this.query = this.adapter;
|
|
45
47
|
await next();
|
|
46
48
|
return;
|
|
@@ -75,7 +77,7 @@ class Knex {
|
|
|
75
77
|
});
|
|
76
78
|
this.query = this.adapter;
|
|
77
79
|
this.logger.debug('connected');
|
|
78
|
-
|
|
80
|
+
global.FaasJS_Knex[this.name] = this;
|
|
79
81
|
await next();
|
|
80
82
|
}
|
|
81
83
|
async raw(sql, bindings = []) {
|
|
@@ -95,8 +97,8 @@ class Knex {
|
|
|
95
97
|
}
|
|
96
98
|
async quit() {
|
|
97
99
|
try {
|
|
98
|
-
await
|
|
99
|
-
delete
|
|
100
|
+
await global.FaasJS_Knex[this.name].adapter.destroy();
|
|
101
|
+
delete global.FaasJS_Knex[this.name];
|
|
100
102
|
}
|
|
101
103
|
catch (error) {
|
|
102
104
|
console.error(error);
|
|
@@ -105,8 +107,8 @@ class Knex {
|
|
|
105
107
|
}
|
|
106
108
|
function useKnex(config) {
|
|
107
109
|
const name = (config === null || config === void 0 ? void 0 : config.name) || Name;
|
|
108
|
-
if (
|
|
109
|
-
return usePlugin(
|
|
110
|
+
if (global.FaasJS_Knex[name])
|
|
111
|
+
return usePlugin(global.FaasJS_Knex[name]);
|
|
110
112
|
return usePlugin(new Knex(config));
|
|
111
113
|
}
|
|
112
114
|
function query(table) {
|
package/lib/index.js
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var func = require('@faasjs/func');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var logger = require('@faasjs/logger');
|
|
7
|
+
var deep_merge = require('@faasjs/deep_merge');
|
|
8
8
|
var knex = require('knex');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
11
|
|
|
12
|
-
var Logger__default = /*#__PURE__*/_interopDefaultLegacy(Logger);
|
|
13
|
-
var deepMerge__default = /*#__PURE__*/_interopDefaultLegacy(deepMerge);
|
|
14
12
|
var knex__default = /*#__PURE__*/_interopDefaultLegacy(knex);
|
|
15
13
|
|
|
16
14
|
const Name = 'knex';
|
|
17
|
-
|
|
15
|
+
if (!global['FaasJS_Knex']) {
|
|
16
|
+
global.FaasJS_Knex = {};
|
|
17
|
+
}
|
|
18
18
|
/**
|
|
19
19
|
* Knex 插件
|
|
20
20
|
*/
|
|
@@ -36,7 +36,7 @@ class Knex {
|
|
|
36
36
|
this.name = this.type;
|
|
37
37
|
this.config = Object.create(null);
|
|
38
38
|
}
|
|
39
|
-
this.logger = new
|
|
39
|
+
this.logger = new logger.Logger(this.name);
|
|
40
40
|
}
|
|
41
41
|
async onDeploy(data, next) {
|
|
42
42
|
const client = data.config.plugins[this.name].config.client;
|
|
@@ -48,9 +48,9 @@ class Knex {
|
|
|
48
48
|
}
|
|
49
49
|
async onMount(data, next) {
|
|
50
50
|
var _a;
|
|
51
|
-
if (
|
|
52
|
-
this.config =
|
|
53
|
-
this.adapter =
|
|
51
|
+
if (global.FaasJS_Knex[this.name]) {
|
|
52
|
+
this.config = global.FaasJS_Knex[this.name].config;
|
|
53
|
+
this.adapter = global.FaasJS_Knex[this.name].adapter;
|
|
54
54
|
this.query = this.adapter;
|
|
55
55
|
await next();
|
|
56
56
|
return;
|
|
@@ -70,8 +70,8 @@ class Knex {
|
|
|
70
70
|
this.config[key] = value;
|
|
71
71
|
}
|
|
72
72
|
if (data.config.plugins && ((_a = data.config.plugins[this.name]) === null || _a === void 0 ? void 0 : _a.config))
|
|
73
|
-
this.config =
|
|
74
|
-
this.adapter = knex__default[
|
|
73
|
+
this.config = deep_merge.deepMerge(data.config.plugins[this.name].config, this.config);
|
|
74
|
+
this.adapter = knex__default["default"](this.config);
|
|
75
75
|
this.adapter
|
|
76
76
|
.on('query', ({ sql, __knexQueryUid, bindings }) => {
|
|
77
77
|
this.logger.time(`Knex${__knexQueryUid}`);
|
|
@@ -85,7 +85,7 @@ class Knex {
|
|
|
85
85
|
});
|
|
86
86
|
this.query = this.adapter;
|
|
87
87
|
this.logger.debug('connected');
|
|
88
|
-
|
|
88
|
+
global.FaasJS_Knex[this.name] = this;
|
|
89
89
|
await next();
|
|
90
90
|
}
|
|
91
91
|
async raw(sql, bindings = []) {
|
|
@@ -105,8 +105,8 @@ class Knex {
|
|
|
105
105
|
}
|
|
106
106
|
async quit() {
|
|
107
107
|
try {
|
|
108
|
-
await
|
|
109
|
-
delete
|
|
108
|
+
await global.FaasJS_Knex[this.name].adapter.destroy();
|
|
109
|
+
delete global.FaasJS_Knex[this.name];
|
|
110
110
|
}
|
|
111
111
|
catch (error) {
|
|
112
112
|
console.error(error);
|
|
@@ -115,8 +115,8 @@ class Knex {
|
|
|
115
115
|
}
|
|
116
116
|
function useKnex(config) {
|
|
117
117
|
const name = (config === null || config === void 0 ? void 0 : config.name) || Name;
|
|
118
|
-
if (
|
|
119
|
-
return func.usePlugin(
|
|
118
|
+
if (global.FaasJS_Knex[name])
|
|
119
|
+
return func.usePlugin(global.FaasJS_Knex[name]);
|
|
120
120
|
return func.usePlugin(new Knex(config));
|
|
121
121
|
}
|
|
122
122
|
function query(table) {
|
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.253",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"lib"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@faasjs/deep_merge": "^0.0.2-beta.
|
|
22
|
-
"@faasjs/logger": "^0.0.2-beta.
|
|
21
|
+
"@faasjs/deep_merge": "^0.0.2-beta.244",
|
|
22
|
+
"@faasjs/logger": "^0.0.2-beta.243",
|
|
23
23
|
"knex": "*"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@faasjs/func": "^0.0.2-beta.
|
|
26
|
+
"@faasjs/func": "^0.0.2-beta.253",
|
|
27
27
|
"@types/debug": "*",
|
|
28
28
|
"@types/jest": "*",
|
|
29
29
|
"@types/mysql": "*",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"sqlite3": "*",
|
|
38
38
|
"typescript": "*"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e1a54598c7bc4f74d645f5a85c58ec1d1f1c9c16"
|
|
41
41
|
}
|