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.30.0",
"version": "5.31.0",
"description": "The Athenna database handler for SQL/NoSQL.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
19 changes: 18 additions & 1 deletion src/models/builders/ModelQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import type { Driver } from '#src/database/drivers/Driver'
import { QueryBuilder } from '#src/database/builders/QueryBuilder'
import type { ModelSchema } from '#src/models/schemas/ModelSchema'
import { ModelGenerator } from '#src/models/factories/ModelGenerator'
import type { Transaction } from '#src/database/transactions/Transaction'
import { UniqueValueException } from '#src/exceptions/UniqueValueException'
import { HasOneRelation } from '#src/models/relations/HasOne/HasOneRelation'
import { NotFoundDataException } from '#src/exceptions/NotFoundDataException'
import { HasManyRelation } from '#src/models/relations/HasMany/HasManyRelation'
import { NullableValueException } from '#src/exceptions/NullableValueException'
import { BelongsToRelation } from '#src/models/relations/BelongsTo/BelongsToRelation'
import { BelongsToManyRelation } from '../relations/BelongsToMany/BelongsToManyRelation.js'
import { BelongsToManyRelation } from '#src/models/relations/BelongsToMany/BelongsToManyRelation'

export class ModelQueryBuilder<
M extends BaseModel = any,
Expand Down Expand Up @@ -73,6 +74,22 @@ export class ModelQueryBuilder<
this.setPrimaryKey(this.primaryKeyName)
}

/**
* Define a transaction to be used by the model query builder.
*/
public setTransaction(trx: Transaction) {
return this.setDriver(trx.driver, this.Model.table())
}

/**
* Set a different driver to the model query builder.
*/
public setDriver(driver: Driver, tableName?: string) {
super.setDriver(driver, tableName)

return this
}

/**
* Calculate the average of a given column.
*/
Expand Down