Skip to content

Commit

Permalink
refactor: deprecate useTransaction method usage on query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 14, 2023
1 parent b44d15e commit 223db39
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/database/query_builder/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ export class DatabaseQueryBuilder extends Chainable implements DatabaseQueryBuil
}

/**
* Run query inside the given transaction
* @deprecated
* Do not use this method. Instead create a query using the
* transaction client directly.
*
* ```ts
* trx.query()
* ```
*/
useTransaction(transaction: TransactionClientContract): this {
this.knexQuery.transacting(transaction.knexClient)
Expand Down
8 changes: 7 additions & 1 deletion src/database/query_builder/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ export class InsertQueryBuilder extends Macroable implements InsertQueryBuilderC
}

/**
* Run query inside the given transaction
* @deprecated
* Do not use this method. Instead create a query using the
* transaction client directly.
*
* ```ts
* trx.insertQuery()
* ```
*/
useTransaction(transaction: TransactionClientContract) {
this.knexQuery.transacting(transaction.knexClient)
Expand Down
8 changes: 7 additions & 1 deletion src/database/query_builder/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ export class RawQueryBuilder implements RawQueryBuilderContract {
}

/**
* Run query inside the given transaction
* @deprecated
* Do not use this method. Instead create a query using the
* transaction client directly.
*
* ```ts
* trx.rawQuery()
* ```
*/
useTransaction(transaction: TransactionClientContract) {
this.knexQuery.transacting(transaction.knexClient)
Expand Down
7 changes: 6 additions & 1 deletion src/orm/query_builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,12 @@ export class ModelQueryBuilder
}

/**
* Run query inside the given transaction
* @deprecated
* Do not use this method. Instead create a query with options.client
*
* ```ts
* Model.query({ client: trx })
* ```
*/
useTransaction(transaction: TransactionClientContract) {
this.knexQuery.transacting(transaction.knexClient)
Expand Down
9 changes: 9 additions & 0 deletions src/types/querybuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,15 @@ export interface InsertQueryBuilderContract<Result = any>
export interface ExcutableQueryBuilderContract<Result> extends Promise<Result> {
debug(debug: boolean): this
timeout(time: number, options?: { cancel: boolean }): this
/**
* @deprecated
* Do not use this method. Instead create a query with options.client
*
* ```ts
* Model.query({ client: trx })
* Database.query({ client: trx })
* ```
*/
useTransaction(trx: TransactionClientContract): this
reporterData(data: any): this
toQuery(): string
Expand Down

0 comments on commit 223db39

Please sign in to comment.