Skip to content

Commit 72901c7

Browse files
authored
Merge pull request #193 from AthennaIO/develop
feat: add or clause to ObjectId
2 parents 7ec5f24 + 36d87ba commit 72901c7

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/database",
3-
"version": "5.14.0",
3+
"version": "5.15.0",
44
"description": "The Athenna database handler for SQL/NoSQL.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",

src/database/drivers/MongoDriver.ts

+32
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,14 @@ export class MongoDriver extends Driver<Connection, Collection> {
12121212
* Set a where in statement in your query.
12131213
*/
12141214
public whereIn(column: string, values: any[]) {
1215+
values = values.flatMap(value => {
1216+
if (ObjectId.isValid(value)) {
1217+
return [value, ObjectId.ifValidSwap(value)]
1218+
}
1219+
1220+
return [value]
1221+
})
1222+
12151223
this._where.push({ [column]: { $in: values } })
12161224

12171225
return this
@@ -1221,6 +1229,14 @@ export class MongoDriver extends Driver<Connection, Collection> {
12211229
* Set a where not in statement in your query.
12221230
*/
12231231
public whereNotIn(column: string, values: any[]) {
1232+
values = values.flatMap(value => {
1233+
if (ObjectId.isValid(value)) {
1234+
return [value, ObjectId.ifValidSwap(value)]
1235+
}
1236+
1237+
return [value]
1238+
})
1239+
12241240
this._where.push({ [column]: { $nin: values } })
12251241

12261242
return this
@@ -1344,6 +1360,14 @@ export class MongoDriver extends Driver<Connection, Collection> {
13441360
* Set an or where in statement in your query.
13451361
*/
13461362
public orWhereIn(column: string, values: any[]) {
1363+
values = values.flatMap(value => {
1364+
if (ObjectId.isValid(value)) {
1365+
return [value, ObjectId.ifValidSwap(value)]
1366+
}
1367+
1368+
return [value]
1369+
})
1370+
13471371
this._orWhere.push({ [column]: { $in: values } })
13481372

13491373
return this
@@ -1353,6 +1377,14 @@ export class MongoDriver extends Driver<Connection, Collection> {
13531377
* Set an or where not in statement in your query.
13541378
*/
13551379
public orWhereNotIn(column: string, values: any[]) {
1380+
values = values.flatMap(value => {
1381+
if (ObjectId.isValid(value)) {
1382+
return [value, ObjectId.ifValidSwap(value)]
1383+
}
1384+
1385+
return [value]
1386+
})
1387+
13561388
this._orWhere.push({ [column]: { $nin: values } })
13571389

13581390
return this

0 commit comments

Comments
 (0)