* Execute queries within a transaction * @param input a callback or a query list * @param options to set timeouts (callback) * @returns
(input: any, options?: any)
| 876 | * @returns |
| 877 | */ |
| 878 | $transaction(input: any, options?: any) { |
| 879 | let callback: () => Promise<any> |
| 880 | |
| 881 | // iTx - Interactive transaction |
| 882 | if (typeof input === 'function') { |
| 883 | if (this._engineConfig.adapter?.adapterName === '@prisma/adapter-d1') { |
| 884 | callback = () => { |
| 885 | throw new Error( |
| 886 | 'Cloudflare D1 does not support interactive transactions. We recommend you to refactor your queries with that limitation in mind, and use batch transactions with `prisma.$transactions([])` where applicable.', |
| 887 | ) |
| 888 | } |
| 889 | } else if (config.activeProvider === 'mongodb' && getItxScopeContext(this).kind === 'nested') { |
| 890 | callback = () => { |
| 891 | throw new PrismaClientValidationError( |
| 892 | `The ${config.activeProvider} provider does not support nested transactions`, |
| 893 | { clientVersion: this._clientVersion }, |
| 894 | ) |
| 895 | } |
| 896 | } else { |
| 897 | callback = () => this._transactionWithCallback({ callback: input, options }) |
| 898 | } |
| 899 | } else { |
| 900 | // Batch transaction |
| 901 | callback = () => this._transactionWithArray({ promises: input, options }) |
| 902 | } |
| 903 | |
| 904 | const spanOptions = { |
| 905 | name: 'transaction', |
| 906 | attributes: { method: '$transaction' }, |
| 907 | } |
| 908 | |
| 909 | return this._tracingHelper.runInChildSpan(spanOptions, callback) |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Runs the middlewares over params before executing a request |