Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/database",
"version": "5.11.0",
"version": "5.12.0",
"description": "The Athenna database handler for SQL/NoSQL.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
48 changes: 2 additions & 46 deletions src/database/drivers/MongoDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { WrongMethodException } from '#src/exceptions/WrongMethodException'
import { MONGO_OPERATIONS_DICTIONARY } from '#src/constants/MongoOperationsDictionary'
import { NotConnectedDatabaseException } from '#src/exceptions/NotConnectedDatabaseException'
import { NotImplementedMethodException } from '#src/exceptions/NotImplementedMethodException'
import { ObjectId } from '#src/helpers/ObjectId'

export class MongoDriver extends Driver<Connection, Collection> {
public primaryKey = '_id'
Expand Down Expand Up @@ -1145,23 +1144,19 @@ export class MongoDriver extends Driver<Connection, Collection> {
}

if (operation === undefined) {
this._where.push(this.parseObjectIDToString(statement))
this._where.push(statement)

return this
}

if (value === undefined) {
operation = this.parseObjectIDToString(operation)

this._where.push({
[statement]: this.setOperator(operation, '=')
})

return this
}

value = this.parseObjectIDToString(value)

this._where.push({ [statement]: this.setOperator(value, operation) })

return this
Expand Down Expand Up @@ -1216,8 +1211,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where in statement in your query.
*/
public whereIn(column: string, values: any[]) {
values = this.parseObjectIDToString(values)

this._where.push({ [column]: { $in: values } })

return this
Expand All @@ -1227,8 +1220,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where not in statement in your query.
*/
public whereNotIn(column: string, values: any[]) {
values = this.parseObjectIDToString(values)

this._where.push({ [column]: { $nin: values } })

return this
Expand All @@ -1238,8 +1229,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where between statement in your query.
*/
public whereBetween(column: string, values: [any, any]) {
values = this.parseObjectIDToString(values)

this._where.push({ [column]: { $gte: values[0], $lte: values[1] } })

return this
Expand All @@ -1249,8 +1238,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where not between statement in your query.
*/
public whereNotBetween(column: string, values: [any, any]) {
values = this.parseObjectIDToString(values)

this._where.push({
[column]: { $not: { $gte: values[0], $lte: values[1] } }
})
Expand Down Expand Up @@ -1291,21 +1278,17 @@ export class MongoDriver extends Driver<Connection, Collection> {
}

if (operation === undefined) {
this._orWhere.push(this.parseObjectIDToString(statement))
this._orWhere.push(statement)

return this
}

if (value === undefined) {
operation = this.parseObjectIDToString(operation)

this._orWhere.push({ [statement]: this.setOperator(operation, '=') })

return this
}

value = this.parseObjectIDToString(value)

this._orWhere.push({ [statement]: this.setOperator(value, operation) })

return this
Expand Down Expand Up @@ -1360,8 +1343,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set an or where in statement in your query.
*/
public orWhereIn(column: string, values: any[]) {
values = this.parseObjectIDToString(values)

this._orWhere.push({ [column]: { $in: values } })

return this
Expand All @@ -1371,8 +1352,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set an or where not in statement in your query.
*/
public orWhereNotIn(column: string, values: any[]) {
values = this.parseObjectIDToString(values)

this._orWhere.push({ [column]: { $nin: values } })

return this
Expand All @@ -1382,8 +1361,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set an or where between statement in your query.
*/
public orWhereBetween(column: string, values: [any, any]) {
values = this.parseObjectIDToString(values)

this._orWhere.push({ [column]: { $gte: values[0], $lte: values[1] } })

return this
Expand All @@ -1393,8 +1370,6 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set an or where not between statement in your query.
*/
public orWhereNotBetween(column: string, values: [any, any]) {
values = this.parseObjectIDToString(values)

this._orWhere.push({
[column]: { $not: { $gte: values[0], $lte: values[1] } }
})
Expand Down Expand Up @@ -1565,23 +1540,4 @@ export class MongoDriver extends Driver<Connection, Collection> {

return pipeline
}

/**
* Parse a valid ObjectID string to an ObjectID object.
*/
private parseObjectIDToString(statement: unknown | string) {
if (Is.Array(statement)) {
return statement.map(value => this.parseObjectIDToString(value))
}

if (Is.Object(statement)) {
Object.keys(statement).forEach(key => {
statement[key] = ObjectId.ifValidSwap(statement[key])
})

return statement
}

return ObjectId.ifValidSwap(statement)
}
}