Skip to content

Commit

Permalink
fix: merge default options into user defined options instead of overr…
Browse files Browse the repository at this point in the history
…iding them
  • Loading branch information
sam-artuso committed Apr 13, 2024
1 parent e24c5a6 commit a63db74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ ClsModule.forRoot({

The `tx` property on the `TransactionHost<TransactionalAdapterPgPromise>` is typed as [`Database`](https://vitaly-t.github.io/pg-promise/Database.html).

`@Transactional()` takes an optional argument that is the same as the `option` argument to `Database.tx()` in `pg-promise` ([docs](https://vitaly-t.github.io/pg-promise/Database.html#tx)).

## Example

```ts title="user.service.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export interface PgPromiseTransactionalAdapterOptions {
*/
dbInstanceToken: any;

/**
* Default options for the transaction. These will be merged with any transaction-specific options
* passed to the `@Transactional` decorator or the `TransactionHost#withTransaction` method.
*/
defaultTxOptions?: TxOptions;
}

Expand All @@ -33,7 +37,7 @@ export class TransactionalAdapterPgPromise
setClient: (client?: Database) => void,
) => {
return pgPromiseDbInstance.tx(
options ?? this.defaultTxOptions ?? {},
{ ...this.defaultTxOptions, ...options },
(tx) => {
setClient(tx as unknown as Database);
return fn();
Expand Down

0 comments on commit a63db74

Please sign in to comment.