Skip to content

Commit

Permalink
update deps (#131)
Browse files Browse the repository at this point in the history
<!-- CLICK "Preview" FOR INSTRUCTIONS IN A MORE READABLE FORMAT -->

## Proposed changes

Describe the big picture of your changes here to communicate to the 
maintainers why we should accept this pull request. If it fixes a bug 
or resolves a feature request, be sure to link to that issue.

## Types of changes

What types of changes does your code introduce?

_Put an `x` in the boxes that apply_

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)

## Checklist

_Put an `x` in the boxes that apply. You can also fill these out after 
creating the PR. If you're unsure about any of them, don't hesitate to
ask.
We're here to help! This is simply a reminder of what we are going to
look
for before merging your code._

- [ ] I have read the
[CONTRIBUTING](https://github.com/AthennaIO/Database/blob/master/CONTRIBUTING.md)
documentation
- [ ] Lint and unit tests pass locally with my changes
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added necessary documentation (if appropriate)

## Further comments

If this is a relatively large or complex change, kick off the discussion
by
explaining why you chose the solution you did and what alternatives you 
considered, etc...
  • Loading branch information
jlenon7 authored Jan 7, 2024
1 parent 8ffb5ff commit 41647d7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 49 deletions.
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": "4.24.0",
"version": "4.25.0",
"description": "The Athenna database handler for SQL/NoSQL.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
65 changes: 20 additions & 45 deletions src/database/drivers/MongoDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
/**
* The where clause used in update queries.
*/
private _where: Record<string, any> = {}
private _where: Record<string, any>[] = []

/**
* The or where clause used in update queries.
Expand Down Expand Up @@ -1059,21 +1059,18 @@ export class MongoDriver extends Driver<Connection, Collection> {
}

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

return this
}

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

return this
}

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

return this
}
Expand Down Expand Up @@ -1127,7 +1124,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where in statement in your query.
*/
public whereIn(column: string, values: any[]) {
this._where[column] = { $in: values }
this._where.push({ [column]: { $in: values } })

return this
}
Expand All @@ -1136,7 +1133,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where not in statement in your query.
*/
public whereNotIn(column: string, values: any[]) {
this._where[column] = { $nin: values }
this._where.push({ [column]: { $nin: values } })

return this
}
Expand All @@ -1145,7 +1142,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where between statement in your query.
*/
public whereBetween(column: string, values: [any, any]) {
this._where[column] = { $gte: values[0], $lte: values[1] }
this._where.push({ [column]: { $gte: values[0], $lte: values[1] } })

return this
}
Expand All @@ -1154,7 +1151,9 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where not between statement in your query.
*/
public whereNotBetween(column: string, values: [any, any]) {
this._where[column] = { $not: { $gte: values[0], $lte: values[1] } }
this._where.push({
[column]: { $not: { $gte: values[0], $lte: values[1] } }
})

return this
}
Expand All @@ -1163,7 +1162,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where null statement in your query.
*/
public whereNull(column: string) {
this._where[column] = null
this._where.push({ [column]: null })

return this
}
Expand All @@ -1172,7 +1171,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
* Set a where not null statement in your query.
*/
public whereNotNull(column: string) {
this._where[column] = { $ne: null }
this._where.push({ [column]: { $ne: null } })

return this
}
Expand Down Expand Up @@ -1407,20 +1406,18 @@ export class MongoDriver extends Driver<Connection, Collection> {
clearOrWhere: true
})

if (Is.Empty(this._orWhere)) {
const where = Json.copy(this._where)
const where: any = {}

if (options.clearWhere) {
this._where = {}
}

return where
if (!Is.Empty(this._where)) {
where.$and = Json.copy(this._where)
}

const where = { $or: [Json.copy(this._where), ...Json.copy(this._orWhere)] }
if (!Is.Empty(this._orWhere)) {
where.$or = Json.copy(this._orWhere)
}

if (options.clearWhere) {
this._where = {}
this._where = []
}

if (options.clearOrWhere) {
Expand Down Expand Up @@ -1452,29 +1449,7 @@ export class MongoDriver extends Driver<Connection, Collection> {
this.pipeline = []
}

if (!Is.Empty(this._where)) {
const $match = Json.copy(this._where)

pipeline.push({ $match })
}

if (!Is.Empty(this._orWhere)) {
const $match = { $or: Json.copy(this._orWhere) }

if (!Is.Empty(this._where)) {
$match.$or.unshift(this._where)
}

pipeline.push({ $match })
}

if (options.clearWhere) {
this._where = {}
}

if (options.clearOrWhere) {
this._orWhere = []
}
pipeline.push({ $match: this.createWhere(options) })

return pipeline
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/drivers/MongoDriverTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ export default class MongoDriverTest {

this.driver.table('users').select('*').dump()

assert.calledWith(console.log, { where: {}, orWhere: [], pipeline: [] })
assert.calledWith(console.log, { where: [], orWhere: [], pipeline: [] })
}

@Test()
Expand Down

0 comments on commit 41647d7

Please sign in to comment.