You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/drizzle/drizzle.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -274,6 +274,56 @@ return results
274
274
275
275
---
276
276
277
+
## JSONB queries with encrypted data
278
+
279
+
Protect.js supports querying encrypted JSON columns using JSONB operators. These operators require `searchableJson: true` and `dataType: 'json'` in the column's `encryptedType` config.
280
+
281
+
> [!TIP]
282
+
> For details on the low-level `encryptQuery` API and JSONB query types (`steVecSelector`, `steVecTerm`), see the [Searchable encryption with PostgreSQL](../searchable-encryption-postgres.md#jsonb-queries-with-searchablejson-recommended) reference.
283
+
284
+
### Check path existence with `jsonbPathExists`
285
+
286
+
Use `jsonbPathExists` to check if a JSONPath exists in the JSONB data. This returns a boolean and can be used directly in `WHERE` clauses. This is equivalent to the PostgreSQL `jsonb_path_exists` function.
Use `jsonbPathQueryFirst` to extract the first value at a given JSONPath in a `SELECT` expression. This is equivalent to the PostgreSQL `jsonb_path_query_first` function.
298
+
299
+
> [!NOTE]
300
+
> `jsonbPathQueryFirst` returns an encrypted value, not a boolean. Use it in `SELECT` expressions, not directly in `WHERE` clauses. Use `jsonbPathExists` to filter rows by path existence.
301
+
302
+
### Get value with `jsonbGet`
303
+
304
+
Use `jsonbGet` to get a value using the JSONB `->` operator in a `SELECT` expression.
305
+
306
+
> [!NOTE]
307
+
> `jsonbGet` returns an encrypted value, not a boolean. Use it in `SELECT` expressions, not directly in `WHERE` clauses. Use `jsonbPathExists` to filter rows by path existence.
308
+
309
+
### Combine JSONB operators with other conditions
310
+
311
+
JSONB operators can be combined with other Protect operators using `and` and `or`. Use `jsonbPathExists` for boolean conditions in `WHERE` clauses.
Copy file name to clipboardExpand all lines: docs/reference/searchable-encryption-postgres.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,9 @@ console.log(term.data) // array of search terms
116
116
117
117
### JSONB queries with searchableJson (recommended)
118
118
119
+
> [!TIP]
120
+
> **Using Drizzle ORM?** The `@cipherstash/drizzle` package provides higher-level JSONB operators (`jsonbPathQueryFirst`, `jsonbGet`, `jsonbPathExists`) that handle encryption automatically. See the [Drizzle JSONB query examples](./drizzle/drizzle.md#jsonb-queries-with-encrypted-data).
121
+
119
122
For columns storing JSON data, `.searchableJson()` is the recommended approach. It enables encrypted JSONB queries and automatically infers the correct query operation from the plaintext value type.
120
123
121
124
Use `encryptQuery` to create encrypted query terms for JSONB columns:
0 commit comments