kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.85k stars 276 forks source link

How to access "message" OR "code" in my code #1196

Closed patrickReiis closed 1 month ago

patrickReiis commented 1 month ago

Take for example the following query (it returns an empty array):

await kysely.selectFrom('nostr_events').select('id').where('search', '@@', sql`phraseto_tsquery('what')`).execute()

Since what is a stop word and it's the only only word, Postgres ignores this query (which is ok).

When I run the query mentioned I see this in my logs:

{
  severity_local: "NOTICE",
  severity: "NOTICE",
  code: "00000",
  message: "text-search query contains only stop words or doesn't contain lexemes, ignored",
  file: "tsquery_cleanup.c",
  line: "406",
  routine: "cleanup_tsquery_stopwords"
}

I would like to be able to get the code or message before or after executing, so I can throw an error in my code so the frontend can handle it. Thanks.

koskimas commented 1 month ago

That's logged by the pg driver. There's no way to access it.