@faasjs/knex 0.0.3-beta.99 → 0.0.4-beta.2
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/README.md +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -49
- package/dist/index.mjs +49 -49
- package/package.json +11 -7
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -20,7 +20,7 @@ declare class Knex implements Plugin {
|
|
|
20
20
|
onMount(data: MountData, next: Next): Promise<void>;
|
|
21
21
|
onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
|
|
22
22
|
raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
|
|
23
|
-
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?:
|
|
23
|
+
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
|
|
24
24
|
schema(): Knex$1.SchemaBuilder;
|
|
25
25
|
quit(): Promise<void>;
|
|
26
26
|
}
|
|
@@ -35,7 +35,7 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
|
|
|
35
35
|
_unionProps: never;
|
|
36
36
|
}[]>;
|
|
37
37
|
declare function query<TName extends {} = any, TResult = any[]>(table: string): Knex$1.QueryBuilder<TName, TResult>;
|
|
38
|
-
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?:
|
|
38
|
+
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
|
|
39
39
|
declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult>;
|
|
40
40
|
|
|
41
41
|
export { Knex, KnexConfig, query, raw, transaction, useKnex };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare class Knex implements Plugin {
|
|
|
20
20
|
onMount(data: MountData, next: Next): Promise<void>;
|
|
21
21
|
onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
|
|
22
22
|
raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
|
|
23
|
-
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?:
|
|
23
|
+
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
|
|
24
24
|
schema(): Knex$1.SchemaBuilder;
|
|
25
25
|
quit(): Promise<void>;
|
|
26
26
|
}
|
|
@@ -35,7 +35,7 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
|
|
|
35
35
|
_unionProps: never;
|
|
36
36
|
}[]>;
|
|
37
37
|
declare function query<TName extends {} = any, TResult = any[]>(table: string): Knex$1.QueryBuilder<TName, TResult>;
|
|
38
|
-
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?:
|
|
38
|
+
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
|
|
39
39
|
declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult>;
|
|
40
40
|
|
|
41
41
|
export { Knex, KnexConfig, query, raw, transaction, useKnex };
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
17
17
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
18
18
|
});
|
|
19
19
|
var Name = "knex";
|
|
20
|
-
if (!global
|
|
20
|
+
if (!global.FaasJS_Knex) {
|
|
21
21
|
global.FaasJS_Knex = {};
|
|
22
22
|
}
|
|
23
23
|
var Knex = class {
|
|
@@ -41,11 +41,11 @@ var Knex = class {
|
|
|
41
41
|
data.dependencies["better-sqlite3"] = "*";
|
|
42
42
|
else
|
|
43
43
|
data.dependencies[client] = "*";
|
|
44
|
-
new logger.Logger(this.name).debug(
|
|
44
|
+
new logger.Logger(this.name).debug(`add dependencies: ${client}`);
|
|
45
45
|
await next();
|
|
46
46
|
}
|
|
47
47
|
async onMount(data, next) {
|
|
48
|
-
var _a, _b;
|
|
48
|
+
var _a, _b, _c;
|
|
49
49
|
this.logger = data.logger;
|
|
50
50
|
if (global.FaasJS_Knex[this.name]) {
|
|
51
51
|
this.config = global.FaasJS_Knex[this.name].config;
|
|
@@ -68,65 +68,65 @@ var Knex = class {
|
|
|
68
68
|
} else
|
|
69
69
|
this.config[key] = value;
|
|
70
70
|
}
|
|
71
|
-
if (
|
|
72
|
-
this.config = deep_merge.deepMerge(
|
|
71
|
+
if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
|
|
72
|
+
this.config = deep_merge.deepMerge(
|
|
73
|
+
data.config.plugins[this.name].config,
|
|
74
|
+
this.config
|
|
75
|
+
);
|
|
73
76
|
if (this.config.client === "sqlite3")
|
|
74
77
|
this.config.client = "better-sqlite3";
|
|
75
|
-
if (this.config.client === "pg" && typeof ((
|
|
78
|
+
if (this.config.client === "pg" && typeof ((_c = this.config.pool) == null ? void 0 : _c.propagateCreateError) === "undefined") {
|
|
76
79
|
if (!this.config.pool)
|
|
77
80
|
this.config.pool = /* @__PURE__ */ Object.create(null);
|
|
78
|
-
this.config.pool = Object.assign(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
this.config.pool = Object.assign(
|
|
82
|
+
{
|
|
83
|
+
propagateCreateError: false,
|
|
84
|
+
min: 0,
|
|
85
|
+
max: 10,
|
|
86
|
+
acquireTimeoutMillis: 5e3,
|
|
87
|
+
idleTimeoutMillis: 3e4
|
|
88
|
+
},
|
|
89
|
+
this.config.pool
|
|
90
|
+
);
|
|
85
91
|
if (typeof this.config.connection === "string" && !this.config.connection.includes("json=true"))
|
|
86
|
-
this.config.connection = this.config.connection
|
|
92
|
+
this.config.connection = `${this.config.connection}?json=true`;
|
|
87
93
|
}
|
|
88
94
|
this.adapter = knex__default.default(this.config);
|
|
89
95
|
if (this.config.client === "pg") {
|
|
90
96
|
const pg = __require("pg");
|
|
91
|
-
const intTypes = [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
];
|
|
96
|
-
|
|
97
|
-
pg.types.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"FLOAT8",
|
|
103
|
-
"NUMERIC"
|
|
104
|
-
];
|
|
105
|
-
floatTypes.forEach((t) => pg.types.setTypeParser(
|
|
106
|
-
pg.types.builtins[t],
|
|
107
|
-
(v) => parseFloat(v)
|
|
108
|
-
));
|
|
97
|
+
const intTypes = ["INT2", "INT4", "INT8"];
|
|
98
|
+
intTypes.forEach(
|
|
99
|
+
(t) => pg.types.setTypeParser(pg.types.builtins[t], (v) => parseInt(v))
|
|
100
|
+
);
|
|
101
|
+
const floatTypes = ["FLOAT4", "FLOAT8", "NUMERIC"];
|
|
102
|
+
floatTypes.forEach(
|
|
103
|
+
(t) => pg.types.setTypeParser(
|
|
104
|
+
pg.types.builtins[t],
|
|
105
|
+
(v) => parseFloat(v)
|
|
106
|
+
)
|
|
107
|
+
);
|
|
109
108
|
}
|
|
110
109
|
this.query = this.adapter;
|
|
111
|
-
this.query.on("query", ({
|
|
112
|
-
sql,
|
|
113
|
-
__knexQueryUid,
|
|
114
|
-
bindings
|
|
115
|
-
}) => {
|
|
110
|
+
this.query.on("query", ({ sql, __knexQueryUid, bindings }) => {
|
|
116
111
|
this.logger.time(`Knex${__knexQueryUid}`);
|
|
117
112
|
this.logger.debug("[%s] query begin: %s %j", this.name, sql, bindings);
|
|
118
|
-
}).on("query-response", (response, {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
113
|
+
}).on("query-response", (response, { sql, __knexQueryUid, bindings }) => {
|
|
114
|
+
this.logger.timeEnd(
|
|
115
|
+
`Knex${__knexQueryUid}`,
|
|
116
|
+
"[%s] query done: %s %j %j",
|
|
117
|
+
this.name,
|
|
118
|
+
sql,
|
|
119
|
+
bindings,
|
|
120
|
+
response
|
|
121
|
+
);
|
|
122
|
+
}).on("query-error", (_, { __knexQueryUid, sql, bindings }) => {
|
|
123
|
+
this.logger.timeEnd(
|
|
124
|
+
`Knex${__knexQueryUid}`,
|
|
125
|
+
"[%s] query failed: %s %j",
|
|
126
|
+
this.name,
|
|
127
|
+
sql,
|
|
128
|
+
bindings
|
|
129
|
+
);
|
|
130
130
|
});
|
|
131
131
|
data.logger.debug("[%s] connected", this.name);
|
|
132
132
|
global.FaasJS_Knex[this.name] = this;
|
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
11
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
12
|
});
|
|
13
13
|
var Name = "knex";
|
|
14
|
-
if (!global
|
|
14
|
+
if (!global.FaasJS_Knex) {
|
|
15
15
|
global.FaasJS_Knex = {};
|
|
16
16
|
}
|
|
17
17
|
var Knex = class {
|
|
@@ -35,11 +35,11 @@ var Knex = class {
|
|
|
35
35
|
data.dependencies["better-sqlite3"] = "*";
|
|
36
36
|
else
|
|
37
37
|
data.dependencies[client] = "*";
|
|
38
|
-
new Logger(this.name).debug(
|
|
38
|
+
new Logger(this.name).debug(`add dependencies: ${client}`);
|
|
39
39
|
await next();
|
|
40
40
|
}
|
|
41
41
|
async onMount(data, next) {
|
|
42
|
-
var _a, _b;
|
|
42
|
+
var _a, _b, _c;
|
|
43
43
|
this.logger = data.logger;
|
|
44
44
|
if (global.FaasJS_Knex[this.name]) {
|
|
45
45
|
this.config = global.FaasJS_Knex[this.name].config;
|
|
@@ -62,65 +62,65 @@ var Knex = class {
|
|
|
62
62
|
} else
|
|
63
63
|
this.config[key] = value;
|
|
64
64
|
}
|
|
65
|
-
if (
|
|
66
|
-
this.config = deepMerge(
|
|
65
|
+
if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
|
|
66
|
+
this.config = deepMerge(
|
|
67
|
+
data.config.plugins[this.name].config,
|
|
68
|
+
this.config
|
|
69
|
+
);
|
|
67
70
|
if (this.config.client === "sqlite3")
|
|
68
71
|
this.config.client = "better-sqlite3";
|
|
69
|
-
if (this.config.client === "pg" && typeof ((
|
|
72
|
+
if (this.config.client === "pg" && typeof ((_c = this.config.pool) == null ? void 0 : _c.propagateCreateError) === "undefined") {
|
|
70
73
|
if (!this.config.pool)
|
|
71
74
|
this.config.pool = /* @__PURE__ */ Object.create(null);
|
|
72
|
-
this.config.pool = Object.assign(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
this.config.pool = Object.assign(
|
|
76
|
+
{
|
|
77
|
+
propagateCreateError: false,
|
|
78
|
+
min: 0,
|
|
79
|
+
max: 10,
|
|
80
|
+
acquireTimeoutMillis: 5e3,
|
|
81
|
+
idleTimeoutMillis: 3e4
|
|
82
|
+
},
|
|
83
|
+
this.config.pool
|
|
84
|
+
);
|
|
79
85
|
if (typeof this.config.connection === "string" && !this.config.connection.includes("json=true"))
|
|
80
|
-
this.config.connection = this.config.connection
|
|
86
|
+
this.config.connection = `${this.config.connection}?json=true`;
|
|
81
87
|
}
|
|
82
88
|
this.adapter = knex(this.config);
|
|
83
89
|
if (this.config.client === "pg") {
|
|
84
90
|
const pg = __require("pg");
|
|
85
|
-
const intTypes = [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
];
|
|
90
|
-
|
|
91
|
-
pg.types.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"FLOAT8",
|
|
97
|
-
"NUMERIC"
|
|
98
|
-
];
|
|
99
|
-
floatTypes.forEach((t) => pg.types.setTypeParser(
|
|
100
|
-
pg.types.builtins[t],
|
|
101
|
-
(v) => parseFloat(v)
|
|
102
|
-
));
|
|
91
|
+
const intTypes = ["INT2", "INT4", "INT8"];
|
|
92
|
+
intTypes.forEach(
|
|
93
|
+
(t) => pg.types.setTypeParser(pg.types.builtins[t], (v) => parseInt(v))
|
|
94
|
+
);
|
|
95
|
+
const floatTypes = ["FLOAT4", "FLOAT8", "NUMERIC"];
|
|
96
|
+
floatTypes.forEach(
|
|
97
|
+
(t) => pg.types.setTypeParser(
|
|
98
|
+
pg.types.builtins[t],
|
|
99
|
+
(v) => parseFloat(v)
|
|
100
|
+
)
|
|
101
|
+
);
|
|
103
102
|
}
|
|
104
103
|
this.query = this.adapter;
|
|
105
|
-
this.query.on("query", ({
|
|
106
|
-
sql,
|
|
107
|
-
__knexQueryUid,
|
|
108
|
-
bindings
|
|
109
|
-
}) => {
|
|
104
|
+
this.query.on("query", ({ sql, __knexQueryUid, bindings }) => {
|
|
110
105
|
this.logger.time(`Knex${__knexQueryUid}`);
|
|
111
106
|
this.logger.debug("[%s] query begin: %s %j", this.name, sql, bindings);
|
|
112
|
-
}).on("query-response", (response, {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
}).on("query-response", (response, { sql, __knexQueryUid, bindings }) => {
|
|
108
|
+
this.logger.timeEnd(
|
|
109
|
+
`Knex${__knexQueryUid}`,
|
|
110
|
+
"[%s] query done: %s %j %j",
|
|
111
|
+
this.name,
|
|
112
|
+
sql,
|
|
113
|
+
bindings,
|
|
114
|
+
response
|
|
115
|
+
);
|
|
116
|
+
}).on("query-error", (_, { __knexQueryUid, sql, bindings }) => {
|
|
117
|
+
this.logger.timeEnd(
|
|
118
|
+
`Knex${__knexQueryUid}`,
|
|
119
|
+
"[%s] query failed: %s %j",
|
|
120
|
+
this.name,
|
|
121
|
+
sql,
|
|
122
|
+
bindings
|
|
123
|
+
);
|
|
124
124
|
});
|
|
125
125
|
data.logger.debug("[%s] connected", this.name);
|
|
126
126
|
global.FaasJS_Knex[this.name] = this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/knex",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,13 +20,17 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
|
-
"
|
|
24
|
-
"@faasjs/deep_merge": "0.0.
|
|
25
|
-
"@faasjs/func": "0.0.
|
|
26
|
-
"@faasjs/logger": "0.0.
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@faasjs/deep_merge": "0.0.4-beta.2",
|
|
25
|
+
"@faasjs/func": "0.0.4-beta.2",
|
|
26
|
+
"@faasjs/logger": "0.0.4-beta.2",
|
|
27
27
|
"knex": "*"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
+
"@faasjs/deep_merge": "0.0.4-beta.2",
|
|
31
|
+
"@faasjs/func": "0.0.4-beta.2",
|
|
32
|
+
"@faasjs/logger": "0.0.4-beta.2",
|
|
33
|
+
"knex": "*",
|
|
30
34
|
"@types/mysql": "*",
|
|
31
35
|
"@types/node": "*",
|
|
32
36
|
"@types/pg": "*",
|
|
@@ -36,7 +40,7 @@
|
|
|
36
40
|
"tsd": "*"
|
|
37
41
|
},
|
|
38
42
|
"engines": {
|
|
39
|
-
"npm": ">=
|
|
40
|
-
"node": ">=
|
|
43
|
+
"npm": ">=9.0.0",
|
|
44
|
+
"node": ">=18.0.0"
|
|
41
45
|
}
|
|
42
46
|
}
|