MCPcopy Index your code
hub / github.com/PostHog/posthog / postgresTransaction

Method postgresTransaction

plugin-server/src/utils/db/db.ts:229–254  ·  view source on GitHub ↗
(
        tag: string,
        transaction: (client: PoolClient) => Promise<ReturnType>
    )

Source from the content-addressed store, hash-verified

227 }
228
229 public postgresTransaction<ReturnType>(
230 tag: string,
231 transaction: (client: PoolClient) => Promise<ReturnType>
232 ): Promise<ReturnType> {
233 return instrumentQuery(this.statsd, 'query.postgres_transation', undefined, async () => {
234 const timeout = timeoutGuard(`Postgres slow transaction warning after 30 sec!`)
235 const client = await this.postgres.connect()
236 try {
237 await client.query('BEGIN')
238 const response = await transaction(client)
239 await client.query('COMMIT')
240 return response
241 } catch (e) {
242 await client.query('ROLLBACK')
243
244 // if Postgres is down the ROLLBACK above won't work, but the transaction shouldn't be committed either
245 if (e.message && POSTGRES_UNAVAILABLE_ERROR_MESSAGES.some((message) => e.message.includes(message))) {
246 throw new DependencyUnavailableError(e.message, 'Postgres', e)
247 }
248 throw e
249 } finally {
250 client.release()
251 clearTimeout(timeout)
252 }
253 })
254 }
255
256 public async postgresBulkInsert<T extends Array<any>>(
257 // Should have {VALUES} as a placeholder

Callers 5

createPersonMethod · 0.95
addOrUpdatePublicJobMethod · 0.95
mergePeopleMethod · 0.80
upsertGroupFunction · 0.80

Calls 3

instrumentQueryFunction · 0.90
timeoutGuardFunction · 0.90
queryMethod · 0.45

Tested by

no test coverage detected