zet-lib 1.0.41 → 1.0.42
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/connection.js +7 -2
- package/package.json +1 -1
package/lib/connection.js
CHANGED
|
@@ -138,13 +138,15 @@ connection.insert = async(obj) => {
|
|
|
138
138
|
const datas = [];
|
|
139
139
|
const values = [];
|
|
140
140
|
const arr = [];
|
|
141
|
+
const returning = data.returning || 'RETURNING *'
|
|
142
|
+
delete data.returning;
|
|
141
143
|
for (const key in data) {
|
|
142
144
|
datas.push(key);
|
|
143
145
|
values.push(`$${increment}`)
|
|
144
146
|
arr.push(data[key]);
|
|
145
147
|
increment++;
|
|
146
148
|
}
|
|
147
|
-
const sql = `INSERT INTO "${table}" ("${datas.join('","')}") VALUES (${values.join(",")})
|
|
149
|
+
const sql = `INSERT INTO "${table}" ("${datas.join('","')}") VALUES (${values.join(",")}) ${returning}`;
|
|
148
150
|
/* console.log("ON INSERT " + sql)
|
|
149
151
|
console.log(arr)
|
|
150
152
|
*/
|
|
@@ -163,6 +165,9 @@ connection.insert = async(obj) => {
|
|
|
163
165
|
connection.update = async(obj) => {
|
|
164
166
|
const table = obj.table;
|
|
165
167
|
const data = obj.data;
|
|
168
|
+
const returning = data.returning || 'RETURNING *'
|
|
169
|
+
delete data.returning;
|
|
170
|
+
|
|
166
171
|
const where = obj.where || {}
|
|
167
172
|
//[{field:"your_field",option:"=>",value:"12",operator:"AND"}]
|
|
168
173
|
let whereArray = obj.whereArray || [];
|
|
@@ -194,7 +199,7 @@ connection.update = async(obj) => {
|
|
|
194
199
|
wherequery = wherequery.slice(0, -5);
|
|
195
200
|
}
|
|
196
201
|
const wheres = arr.length ? " WHERE " + wherequery : "";
|
|
197
|
-
const sql = `UPDATE "${table}" SET ${dataArr.join(", ")} ${wheres}
|
|
202
|
+
const sql = `UPDATE "${table}" SET ${dataArr.join(", ")} ${wheres} ${returning}`;
|
|
198
203
|
/* console.log(sql);
|
|
199
204
|
console.log(arr);*/
|
|
200
205
|
try {
|