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

Method postgresQuery

plugin-server/src/utils/db/db.ts:190–227  ·  view source on GitHub ↗
(
        queryString: string,
        values: I | undefined,
        tag: string,
        client?: PoolClient
    )

Source from the content-addressed store, hash-verified

188 // Postgres
189
190 public postgresQuery<R extends QueryResultRow = any, I extends any[] = any[]>(
191 queryString: string,
192 values: I | undefined,
193 tag: string,
194 client?: PoolClient
195 ): Promise<QueryResult<R>> {
196 return instrumentQuery(this.statsd, 'query.postgres', tag, async () => {
197 let fullQuery = ''
198 try {
199 fullQuery = getFinalPostgresQuery(queryString, values as any[])
200 } catch {}
201 const timeout = timeoutGuard('Postgres slow query warning after 30 sec', {
202 queryString,
203 values,
204 fullQuery,
205 })
206
207 // Annotate query string to give context when looking at DB logs
208 queryString = `/* plugin-server:${tag} */ ${queryString}`
209 try {
210 if (client) {
211 return await client.query(queryString, values)
212 } else {
213 return await this.postgres.query(queryString, values)
214 }
215 } catch (error) {
216 if (
217 error.message &&
218 POSTGRES_UNAVAILABLE_ERROR_MESSAGES.some((message) => error.message.includes(message))
219 ) {
220 throw new DependencyUnavailableError(error.message, 'Postgres', error)
221 }
222 throw error
223 } finally {
224 clearTimeout(timeout)
225 }
226 })
227 }
228
229 public postgresTransaction<ReturnType>(
230 tag: string,

Callers 15

postgresBulkInsertMethod · 0.95
getPersonIdMethod · 0.95
fetchPersonsMethod · 0.95
createPersonMethod · 0.95
fetchDistinctIdsMethod · 0.95
addDistinctIdPooledMethod · 0.95
moveDistinctIdsMethod · 0.95
createCohortMethod · 0.95
addPersonToCohortMethod · 0.95

Calls 4

instrumentQueryFunction · 0.90
getFinalPostgresQueryFunction · 0.90
timeoutGuardFunction · 0.90
queryMethod · 0.45

Tested by 3

getStatusFunction · 0.64
fetchPersonByPersonIdFunction · 0.64
getAllHashKeyOverridesFunction · 0.64