@lowdefy/connection-knex 6.0.0 → 7.0.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.
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
-
import
|
|
16
|
+
import getKnex from '../getKnex.js';
|
|
17
17
|
import schema from './schema.js';
|
|
18
18
|
async function KnexBuilder({ request, connection }) {
|
|
19
|
-
let client =
|
|
19
|
+
let client = getKnex(connection);
|
|
20
20
|
if (request.tableName) {
|
|
21
21
|
client = client(request.tableName);
|
|
22
22
|
}
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import
|
|
15
|
+
*/ import getKnex from '../getKnex.js';
|
|
16
16
|
import schema from './schema.js';
|
|
17
17
|
async function KnexRaw({ request, connection }) {
|
|
18
|
-
const client =
|
|
18
|
+
const client = getKnex(connection);
|
|
19
19
|
const res = await client.raw(request.query, request.parameters);
|
|
20
20
|
Object.keys(res).forEach((key)=>{
|
|
21
21
|
if (key.startsWith('_')) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import createKnex from './createKnex.js';
|
|
16
|
+
// Each knex instance owns a connection pool, so an instance per request opened a new pool every
|
|
17
|
+
// time and never released it. Instances are cached for the lifetime of the process, keyed by the
|
|
18
|
+
// connection config, so requests to the same database share one pool.
|
|
19
|
+
const knexClients = new Map();
|
|
20
|
+
function getKnex(connection) {
|
|
21
|
+
const key = JSON.stringify(connection);
|
|
22
|
+
if (!knexClients.has(key)) {
|
|
23
|
+
knexClients.set(key, createKnex(connection));
|
|
24
|
+
}
|
|
25
|
+
return knexClients.get(key);
|
|
26
|
+
}
|
|
27
|
+
async function destroyKnexClients() {
|
|
28
|
+
const clients = [
|
|
29
|
+
...knexClients.values()
|
|
30
|
+
];
|
|
31
|
+
knexClients.clear();
|
|
32
|
+
await Promise.all(clients.map((client)=>client.destroy()));
|
|
33
|
+
}
|
|
34
|
+
export { destroyKnexClients };
|
|
35
|
+
export default getKnex;
|
package/dist/types.js
CHANGED
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
connections: [
|
|
17
17
|
'Knex'
|
|
18
18
|
],
|
|
19
|
+
// Non-scopable: the tenant wall is MongoDB-only, so SQL data sits outside
|
|
20
|
+
// the wall by this declaration - organization scoping, where a deployment
|
|
21
|
+
// needs it, is authored in the queries themselves.
|
|
22
|
+
connectionMetas: {
|
|
23
|
+
Knex: {
|
|
24
|
+
tenant: false
|
|
25
|
+
}
|
|
26
|
+
},
|
|
19
27
|
requests: [
|
|
20
28
|
'KnexBuilder',
|
|
21
29
|
'KnexRaw'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/connection-knex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
28
28
|
},
|
|
29
29
|
"type": "module",
|
|
30
|
+
"sideEffects": [
|
|
31
|
+
"**/*.css"
|
|
32
|
+
],
|
|
30
33
|
"exports": {
|
|
31
34
|
"./connections": "./dist/connections.js",
|
|
32
35
|
"./types": "./dist/types.js"
|
|
@@ -35,17 +38,17 @@
|
|
|
35
38
|
"dist/*"
|
|
36
39
|
],
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"@lowdefy/errors": "
|
|
39
|
-
"@lowdefy/helpers": "
|
|
41
|
+
"@lowdefy/errors": "7.0.0",
|
|
42
|
+
"@lowdefy/helpers": "7.0.0",
|
|
40
43
|
"better-sqlite3": "12.9.0",
|
|
41
44
|
"knex": "3.2.9",
|
|
42
|
-
"mysql2": "3.
|
|
45
|
+
"mysql2": "3.23.1",
|
|
43
46
|
"pg": "8.20.0",
|
|
44
47
|
"tedious": "19.2.1"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
50
|
"@jest/globals": "28.1.3",
|
|
48
|
-
"@lowdefy/ajv": "
|
|
51
|
+
"@lowdefy/ajv": "7.0.0",
|
|
49
52
|
"@swc/cli": "0.8.1",
|
|
50
53
|
"@swc/core": "1.15.32",
|
|
51
54
|
"@swc/jest": "0.2.39",
|