@platformatic/sql-mapper 0.5.1 → 0.6.1

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/entity.js CHANGED
@@ -164,7 +164,13 @@ function createMapper (defaultDb, sql, log, table, fields, primaryKey, relations
164
164
  throw new Error(`Unsupported where clause ${JSON.stringify(where[key])}`)
165
165
  }
166
166
  const fieldWrap = fields[field]
167
- criteria.push(sql`${sql.ident(field)} ${sql.__dangerous__rawValue(operator)} ${computeCriteriaValue(fieldWrap, value[key])}`)
167
+ if (operator === '=' && value[key] === null) {
168
+ criteria.push(sql`${sql.ident(field)} IS NULL`)
169
+ } else if (operator === '<>' && value[key] === null) {
170
+ criteria.push(sql`${sql.ident(field)} IS NOT NULL`)
171
+ } else {
172
+ criteria.push(sql`${sql.ident(field)} ${sql.__dangerous__rawValue(operator)} ${computeCriteriaValue(fieldWrap, value[key])}`)
173
+ }
168
174
  }
169
175
  }
170
176
  return criteria
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-mapper",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "A data mapper utility for SQL databases",
5
5
  "main": "mapper.js",
6
6
  "repository": {
@@ -387,3 +387,50 @@ test('foreign keys', async ({ pass, teardown, same, equal }) => {
387
387
  }])
388
388
  }
389
389
  })
390
+
391
+ test('is NULL', async ({ pass, teardown, same, equal }) => {
392
+ const mapper = await connect({
393
+ ...connInfo,
394
+ log: fakeLogger,
395
+ async onDatabaseLoad (db, sql) {
396
+ teardown(() => db.dispose())
397
+ pass('onDatabaseLoad called')
398
+
399
+ await clear(db, sql)
400
+
401
+ if (isSQLite) {
402
+ await db.query(sql`CREATE TABLE posts (
403
+ id INTEGER PRIMARY KEY,
404
+ title VARCHAR(42)
405
+ );`)
406
+ } else {
407
+ await db.query(sql`CREATE TABLE posts (
408
+ id SERIAL PRIMARY KEY,
409
+ title VARCHAR(42)
410
+ );`)
411
+ }
412
+ }
413
+ })
414
+
415
+ const entity = mapper.entities.post
416
+
417
+ const posts = [{
418
+ title: 'Dog'
419
+ }, {
420
+ title: null
421
+ }]
422
+
423
+ await entity.insert({
424
+ inputs: posts
425
+ })
426
+
427
+ same(await entity.find({ where: { title: { eq: null } } }), [{
428
+ id: '2',
429
+ title: null
430
+ }])
431
+
432
+ same(await entity.find({ where: { title: { neq: null } } }), [{
433
+ id: '1',
434
+ title: 'Dog'
435
+ }])
436
+ })