zet-lib 1.2.25 → 1.2.27

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.
Files changed (2) hide show
  1. package/lib/connection.js +22 -4
  2. package/package.json +1 -1
package/lib/connection.js CHANGED
@@ -73,6 +73,8 @@ const whereFn = (obj) => {
73
73
  arr.push(where[key])
74
74
  increment++
75
75
  }
76
+ //console.log(whereArray);
77
+ let hasWhere = false
76
78
  wherequery = arr.length ? wherequery.join(' AND ') : ''
77
79
  if (whereArray.length) {
78
80
  let andOr = wherequery ? ' AND ' : ''
@@ -89,18 +91,25 @@ const whereFn = (obj) => {
89
91
  if (type == 'date') {
90
92
  field = item.field.indexOf('.') > -1 ? item.field + '::text ' : ` ${item.field}::text `
91
93
  } else {
92
- field = item.field.indexOf('.') > -1 ? item.field : ` "${item.field}" `
94
+ field = item.field.indexOf('.') > -1 ? item.field : item.field ? ` "${item.field}" ` : ''
93
95
  }
94
96
  //is JSON is field is JSON
95
97
  //JSON_CONTAINS(color, '"Red"' ,'$')
96
98
  if (item.isJSON) {
97
99
  wherequery += andOr + ` JSON_CONTAINS(${field}, '"${item.value}"' ,'$') ${operator}`
100
+ hasWhere = true
98
101
  } else {
99
102
  if (type == 'json') {
100
103
  wherequery += andOr + ` JSON_CONTAINS(${field}, '"${item.value}"' ,'$') ${operator}`
104
+ hasWhere = true
101
105
  } else if (type == 'inline') {
102
106
  //select * from attendance where employee_id = 4803 and date IN ('2023-12-21','2023-12-22')
103
- wherequery += andOr + ` ${field} ${item.value} ${operator}`
107
+ if (field) {
108
+ wherequery += andOr + ` ${field} ${item.value} ${operator}`
109
+ } else {
110
+ wherequery += andOr + ` ${item.value} ${operator}`
111
+ }
112
+ hasWhere = true
104
113
  } else {
105
114
  if (item.option.includes('{{value}}')) {
106
115
  item.option = item.option.replace('{{value}}', `$${increment}`)
@@ -123,12 +132,21 @@ const whereFn = (obj) => {
123
132
  })
124
133
  //console.log(arr)
125
134
  }
126
- const wheres = arr.length ? `WHERE ${wherequery}` : ''
127
- return {
135
+ if (arr.length > 0) {
136
+ hasWhere = true
137
+ }
138
+ let wheres = ''
139
+ if (hasWhere) {
140
+ wheres = `WHERE ${wherequery}`
141
+ }
142
+
143
+ let objAll = {
128
144
  where: wheres,
129
145
  arr: arr,
130
146
  increment: increment,
131
147
  }
148
+ //console.log(obj)
149
+ return objAll
132
150
  }
133
151
 
134
152
  connection.results = async (obj) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.2.25",
3
+ "version": "1.2.27",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"