@entergreat/pg-light 1.0.1 → 1.0.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/package.json +20 -5
- package/src/model.js +4 -3
package/package.json
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entergreat/pg-light",
|
|
3
3
|
"description": "Lightweight PostgreSQL client with Mongoose-like models. One-line connection, friendly CRUD API, and raw SQL support.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"files": [
|
|
8
|
-
|
|
7
|
+
"files": [
|
|
8
|
+
"src/"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "restricted"
|
|
12
|
+
},
|
|
9
13
|
"repository": {
|
|
10
14
|
"type": "git",
|
|
11
15
|
"url": "https://github.com/entergreat/pg-light.git"
|
|
12
16
|
},
|
|
13
|
-
"keywords": [
|
|
17
|
+
"keywords": [
|
|
18
|
+
"postgresql",
|
|
19
|
+
"postgres",
|
|
20
|
+
"pg",
|
|
21
|
+
"database",
|
|
22
|
+
"orm",
|
|
23
|
+
"crud",
|
|
24
|
+
"lightweight",
|
|
25
|
+
"entergreat"
|
|
26
|
+
],
|
|
14
27
|
"author": "EnterGreat",
|
|
15
28
|
"license": "ISC",
|
|
16
|
-
"engines": {
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
17
32
|
"dependencies": {
|
|
18
33
|
"pg": "^8.11.3",
|
|
19
34
|
"knex": "^3.1.0",
|
package/src/model.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function buildWhereClause(conditions) {
|
|
1
|
+
function buildWhereClause(conditions, offset = 0) {
|
|
2
2
|
const keys = Object.keys(conditions);
|
|
3
|
-
const whereParts = keys.map((key, idx) => `${key} = $${idx + 1}`);
|
|
3
|
+
const whereParts = keys.map((key, idx) => `${key} = $${idx + 1 + offset}`);
|
|
4
4
|
const values = keys.map(key => conditions[key]);
|
|
5
5
|
return { clause: whereParts.join(' AND '), values };
|
|
6
6
|
}
|
|
@@ -32,7 +32,8 @@ function buildSetClause(data) {
|
|
|
32
32
|
|
|
33
33
|
function buildUpdateQuery(tableName, data, conditions) {
|
|
34
34
|
const { clause: setClause, values: setValues } = buildSetClause(data);
|
|
35
|
-
|
|
35
|
+
// WHERE placeholders continue after the SET placeholders ($n+1, $n+2, ...)
|
|
36
|
+
const { clause: whereClause, values: whereValues } = buildWhereClause(conditions, setValues.length);
|
|
36
37
|
const text = `UPDATE ${tableName} SET ${setClause} WHERE ${whereClause} RETURNING *`;
|
|
37
38
|
const values = [...setValues, ...whereValues];
|
|
38
39
|
return { text, values };
|