@mlagie/sql-connector 3.0.1 → 3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlagie/sql-connector",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "The sql-connector module allows you to manage connections to a MySQL database, define table schemas, and interact with data in a simple and efficient way.",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -106,15 +106,17 @@ function buildWhere(where, values) {
106
106
  for (const [operator, operatorValue] of Object.entries(value)) {
107
107
  if (operator === "IN" || operator === "NOT IN") {
108
108
  const placeholders = operatorValue
109
- .map(() => "?")
109
+ .map((_, i) => getDialect().getPlaceholder(values.length + i))
110
110
  .join(",");
111
111
 
112
112
  conditions.push(
113
113
  `${getDialect().escape(key)} ${operator} (${placeholders})`
114
114
  );
115
115
  values.push(...operatorValue);
116
+ } else if (operatorValue === null && (operator === "=" || operator === "!=")) {
117
+ conditions.push(`${getDialect().escape(key)} IS ${operator === "!=" ? "NOT " : ""}NULL`);
116
118
  } else {
117
- conditions.push(`${getDialect().escape(key)} ${operator} ?`);
119
+ conditions.push(`${getDialect().escape(key)} ${operator} ${getDialect().getPlaceholder(values.length)}`);
118
120
  values.push(operatorValue);
119
121
  }
120
122
  }
@@ -122,7 +124,12 @@ function buildWhere(where, values) {
122
124
  }
123
125
  }
124
126
 
125
- conditions.push(`${getDialect().escape(key)} = ?`);
127
+ if (value === null) {
128
+ conditions.push(`${getDialect().escape(key)} IS NULL`);
129
+ continue;
130
+ }
131
+
132
+ conditions.push(`${getDialect().escape(key)} = ${getDialect().getPlaceholder(values.length)}`);
126
133
  values.push(value);
127
134
  }
128
135
 
@@ -169,7 +176,7 @@ function buildQueryParts(options) {
169
176
  if (!Number.isInteger(options.limit) || options.limit < 0) {
170
177
  throw new Error("Invalid LIMIT value");
171
178
  }
172
-
179
+
173
180
  parts.push(`LIMIT ?`);
174
181
  values.push(options.limit);
175
182
  }