@platformatic/sql-mapper 0.34.0 → 0.35.0

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
@@ -202,7 +202,10 @@ function createMapper (defaultDb, sql, log, table, fields, primaryKeys, relation
202
202
  like: 'LIKE',
203
203
  ilike: 'ILIKE',
204
204
  any: 'ANY',
205
- all: 'ALL'
205
+ all: 'ALL',
206
+ contains: '@>',
207
+ contained: '<@',
208
+ overlaps: '&&'
206
209
  }
207
210
 
208
211
  function computeCriteria (opts) {
@@ -235,6 +238,12 @@ function createMapper (defaultDb, sql, log, table, fields, primaryKeys, relation
235
238
  criteria.push(sql`${value[key]} = ANY (${sql.ident(field)})`)
236
239
  } else if (operator === 'ALL') {
237
240
  criteria.push(sql`${value[key]} = ALL (${sql.ident(field)})`)
241
+ } else if (operator === '@>') {
242
+ criteria.push(sql`${sql.ident(field)} @> ${value[key]}`)
243
+ } else if (operator === '<@') {
244
+ criteria.push(sql`${sql.ident(field)} <@ ${value[key]}`)
245
+ } else if (operator === '&&') {
246
+ criteria.push(sql`${sql.ident(field)} && ${value[key]}`)
238
247
  } else {
239
248
  throw new Error('Unsupported operator for Array field')
240
249
  }
@@ -251,7 +260,7 @@ function createMapper (defaultDb, sql, log, table, fields, primaryKeys, relation
251
260
  }
252
261
  const like = operator === 'LIKE' ? sql`LIKE` : queries.hasILIKE ? sql`ILIKE` : sql`LIKE`
253
262
  criteria.push(sql`${leftHand} ${like} ${value[key]}`)
254
- } else if (operator === 'ANY' || operator === 'ALL') {
263
+ } else if (operator === 'ANY' || operator === 'ALL' || operator === '@>' || operator === '<@' || operator === '&&') {
255
264
  throw new Error('Unsupported operator for non Array field')
256
265
  } else {
257
266
  criteria.push(sql`${sql.ident(field)} ${sql.__dangerous__rawValue(operator)} ${computeCriteriaValue(fieldWrap, value[key])}`)
package/mapper.d.ts CHANGED
@@ -103,7 +103,27 @@ export interface WhereCondition {
103
103
  /**
104
104
  * Like ignore-case value.
105
105
  */
106
- ilike?: string
106
+ ilike?: string,
107
+ /**
108
+ * All subquery
109
+ */
110
+ all?: string,
111
+ /**
112
+ * Any subquery
113
+ */
114
+ any?: string
115
+ /**
116
+ * Contains values
117
+ */
118
+ contains?: any[],
119
+ /**
120
+ * Contained by values
121
+ */
122
+ contained?: any[],
123
+ /**
124
+ * Overlaps with values
125
+ */
126
+ overlaps?: any[]
107
127
  }
108
128
  }
109
129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-mapper",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
4
  "description": "A data mapper utility for SQL databases",
5
5
  "main": "mapper.js",
6
6
  "types": "mapper.d.ts",
@@ -29,7 +29,7 @@
29
29
  "camelcase": "^6.3.0",
30
30
  "fastify-plugin": "^4.5.0",
31
31
  "inflected": "^2.1.0",
32
- "@platformatic/types": "0.34.0"
32
+ "@platformatic/types": "0.35.0"
33
33
  },
34
34
  "tsd": {
35
35
  "directory": "test/types"
@@ -1071,6 +1071,27 @@ test('array support (PG)', { skip: !(isPg) }, async ({ teardown, same, rejects }
1071
1071
  }
1072
1072
  }), [{ id: 2, test: [4], checkmark: true }])
1073
1073
 
1074
+ // where contains
1075
+ same(await generatedTest.find({
1076
+ where: {
1077
+ test: { contains: [4] }
1078
+ }
1079
+ }), [{ id: 1, test: [4, 5, 6], checkmark: true }, { id: 2, test: [4], checkmark: true }])
1080
+
1081
+ // where contained
1082
+ same(await generatedTest.find({
1083
+ where: {
1084
+ test: { contained: [4, 5, 6] }
1085
+ }
1086
+ }), [{ id: 1, test: [4, 5, 6], checkmark: true }, { id: 2, test: [4], checkmark: true }])
1087
+
1088
+ // where overlaps
1089
+ same(await generatedTest.find({
1090
+ where: {
1091
+ test: { overlaps: [4] }
1092
+ }
1093
+ }), [{ id: 1, test: [4, 5, 6], checkmark: true }, { id: 2, test: [4], checkmark: true }])
1094
+
1074
1095
  // where eq
1075
1096
  await rejects(generatedTest.find({
1076
1097
  where: {