pg#QueryResultRow TypeScript Examples

The following examples show how to use pg#QueryResultRow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: db.ts    From posthog-foss with MIT License 6 votes vote down vote up
// Postgres

    public postgresQuery<R extends QueryResultRow = any, I extends any[] = any[]>(
        queryString: string,
        values: I | undefined,
        tag: string,
        client?: PoolClient
    ): Promise<QueryResult<R>> {
        return instrumentQuery(this.statsd, 'query.postgres', tag, async () => {
            let fullQuery = ''
            try {
                fullQuery = getFinalPostgresQuery(queryString, values as any[])
            } catch {}
            const timeout = timeoutGuard('Postgres slow query warning after 30 sec', {
                queryString,
                values,
                fullQuery,
            })

            // Annotate query string to give context when looking at DB logs
            queryString = `/* plugin-server:${tag} */ ${queryString}`
            try {
                if (client) {
                    return await client.query(queryString, values)
                } else {
                    return await this.postgres.query(queryString, values)
                }
            } finally {
                clearTimeout(timeout)
            }
        })
    }