MCPcopy
hub / github.com/prisma/prisma / $transaction

Method $transaction

packages/client/src/runtime/getPrismaClient.ts:878–910  ·  view source on GitHub ↗

* Execute queries within a transaction * @param input a callback or a query list * @param options to set timeouts (callback) * @returns

(input: any, options?: any)

Source from the content-addressed store, hash-verified

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

Callers 15

mainFunction · 0.95
mainFunction · 0.95
test.tsFile · 0.80
test.tsFile · 0.80
test.tsFile · 0.80
test.tsFile · 0.80
test.tsFile · 0.80
index.test-d.tsFile · 0.80
runBenchmarksFunction · 0.80
main.tsFile · 0.80
index.tsFile · 0.80
tests.tsFile · 0.80

Calls 4

_transactionWithArrayMethod · 0.95
getItxScopeContextFunction · 0.85
runInChildSpanMethod · 0.65

Tested by 2

mainFunction · 0.76
runBenchmarksFunction · 0.64