Skip to content

Commit 7d3f1f4

Browse files
committed
Implement arr_contains for PostgreSQL
1 parent 3f28ca7 commit 7d3f1f4

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strontium",
3-
"version": "2.9.4",
3+
"version": "2.9.5",
44
"description": "Strontium is a TypeScript toolkit for High Performance API servers built for Production not Projects.",
55
"main": "lib/src/index.js",
66
"types": "lib/src/index.d.ts",

src/query/abstract/Filter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type FieldFilter<P extends keyof T, T> =
1212
$lt?: T[P]
1313
$lte?: T[P]
1414
$contains?: T[P]
15+
$arr_contains?: Array<T[P]>
1516
}
1617
| T[P]
1718

src/query/drivers/sql/SQLFilterCompiler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ export const compileSQLFilter: FilterCompiler<[string, Array<any>]> = (
8080
queries.push(["?? <= ?", [field, subquery.$lte]])
8181
} else if (subquery.$contains !== undefined) {
8282
queries.push(["?? LIKE ?", [field, `%${subquery.$contains}%`]])
83+
} else if (subquery.$arr_cotains !== undefined) {
84+
// This implementation is currently unique to PostgreSQL - We should consider how to add similar functionality to MySQL
85+
queries.push(["?? @> ?", [field, subquery.$arr_cotains]])
8386
} else if (subquery.$eq !== undefined) {
8487
queries.push(["?? = ?", [field, subquery.$eq]])
8588
} else {

src/validation/drivers/validators/isFilter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ const isFieldSelector = (keyValidator: ValidatorFunction<any, any>) =>
4646
$lt: either(isUndefined, keyValidator),
4747
$lte: either(isUndefined, keyValidator),
4848
$contains: either(isUndefined, keyValidator),
49+
$arr_contains: either(isUndefined, isArray(keyValidator)),
4950
})
5051
)

0 commit comments

Comments
 (0)