@hozon/adapter 0.2.0 → 0.2.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/postgres.js CHANGED
@@ -92,8 +92,8 @@ export class AbstractPostgresAdapter {
92
92
  return sql`${expression} ILIKE ${pattern} ESCAPE '\\'`;
93
93
  }
94
94
  arrayIncludesAllPredicate(expression, values) {
95
- // Native jsonb containment: works for string and numeric elements alike. NULL node
96
- // coalesces to an empty array, which is a subset only of another empty set.
95
+ // Native jsonb containment: works for string and numeric elements alike. A node that is
96
+ // not an array (NULL, a scalar or an object) counts as an empty array.
97
97
  // Cast via ::text::jsonb, not a direct ::jsonb: postgres.js infers the parameter's
98
98
  // wire type from a trailing ::jsonb cast and re-encodes the JS string as a jsonb
99
99
  // *string scalar* instead of sending it as text for the server to parse, so a
@@ -102,13 +102,13 @@ export class AbstractPostgresAdapter {
102
102
  // included, contains the empty set) — identical on every backend.
103
103
  const distinct = Array.from(new Set(values));
104
104
  if (distinct.length === 0) return sql`1 = 1`;
105
- return sql`COALESCE(${expression}, '[]'::jsonb) @> ${JSON.stringify(distinct)}::text::jsonb`;
105
+ return sql`(CASE WHEN jsonb_typeof(${expression}) = 'array' THEN ${expression} ELSE '[]'::jsonb END) @> ${JSON.stringify(distinct)}::text::jsonb`;
106
106
  }
107
107
  arrayIncludesAnyPredicate(expression, values) {
108
108
  // An empty list matches nothing; never emit `IN ()`, which Postgres rejects.
109
109
  if (values.length === 0) return sql`1 = 0`;
110
110
  // Elements, not `?|`, so numeric arrays are covered too (`?|` only matches string keys).
111
- return sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(COALESCE(${expression}, '[]'::jsonb)) AS _t WHERE _t IN (${sql.join(values.map((v)=>sql`${v}`))}))`;
111
+ return sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(CASE WHEN jsonb_typeof(${expression}) = 'array' THEN ${expression} ELSE '[]'::jsonb END) AS _t WHERE _t IN (${sql.join(values.map((v)=>sql`${v}`))}))`;
112
112
  }
113
113
  arrayPresencePredicate(expression, mode) {
114
114
  // null/nonNull/empty/nonEmpty must see the true NULL, so the node is never coalesced
package/lib/sqlite.js CHANGED
@@ -101,12 +101,12 @@ export class AbstractSQLiteAdapter {
101
101
  if (distinct.length === 0) return sql`1 = 1`;
102
102
  // NULL/absent node -> json_each yields zero rows -> COUNT(DISTINCT value) = 0, never
103
103
  // equal to a positive set size.
104
- return sql`(SELECT COUNT(DISTINCT value) FROM json_each(COALESCE(${expression}, '[]')) WHERE value IN (${sql.join(distinct.map((v)=>sql`${v}`))})) = ${distinct.length}`;
104
+ return sql`(SELECT COUNT(DISTINCT value) FROM json_each(CASE WHEN json_type(${expression}) = 'array' THEN ${expression} ELSE '[]' END) WHERE value IN (${sql.join(distinct.map((v)=>sql`${v}`))})) = ${distinct.length}`;
105
105
  }
106
106
  arrayIncludesAnyPredicate(expression, values) {
107
107
  // An empty list matches nothing; never emit `IN ()` (portable with Postgres).
108
108
  if (values.length === 0) return sql`1 = 0`;
109
- return sql`EXISTS (SELECT 1 FROM json_each(COALESCE(${expression}, '[]')) WHERE value IN (${sql.join(values.map((v)=>sql`${v}`))}))`;
109
+ return sql`EXISTS (SELECT 1 FROM json_each(CASE WHEN json_type(${expression}) = 'array' THEN ${expression} ELSE '[]' END) WHERE value IN (${sql.join(values.map((v)=>sql`${v}`))}))`;
110
110
  }
111
111
  arrayPresencePredicate(expression, mode) {
112
112
  // null/nonNull/empty/nonEmpty must see the true NULL, so the node is never coalesced
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hozon/adapter",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Database adapter interfaces and dialect behavior for Hozon",
5
5
  "repository": {
6
6
  "type": "git",