Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is there a way to create warpper around sql that would log explain in case of timeout #561

Unanswered
romanoff asked this question in Q&A
Discussion options

As mentioned above I am trying to show explain statement in case sql has timed out. But currently having problem making this work. Currently managed to create wrapper:

const pgSql = postgres({
...params
})
const sqlWrapper = (strings: any, ...args: any[]): any => {
 return pgSql(strings, ...args);
};
Object.assign(sqlWrapper, pgSql);
export const sql: postgres.Sql<
 Record<string, postgres.PostgresType> extends Record<string, postgres.PostgresType>
 ? {}
 : {
 [type in keyof Record<string, postgres.PostgresType>]: Record<string, postgres.PostgresType>[type] extends {
 serialize: (value: infer R) => any;
 parse: (raw: any) => infer R;
 }
 ? R
 : never;
 }
> = sqlWrapper as postgres.Sql<
 Record<string, postgres.PostgresType> extends Record<string, postgres.PostgresType>
 ? {}
 : {
 [type in keyof Record<string, postgres.PostgresType>]: Record<string, postgres.PostgresType>[type] extends {
 serialize: (value: infer R) => any;
 parse: (raw: any) => infer R;
 }
 ? R
 : never;
 }
>;

But I could not catch timeout errors with try catch inside sqlWrapper. As I understand, timeout error would only be available outside in await sql. Is there any way to catch this error inside wrapper? Thanks a lot

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /