Replies: 6 comments 1 reply
-
Can you share some example code to help us better understand? Youre looking to see if a specific field is part of a query? |
Beta Was this translation helpful? Give feedback.
-
How to find Query from QueryEvent sqlQuery, _ := evt.FormattedQuery() sqlQuery, _ := evt.UnformattedQuery() In both the case string(sqlQuery) return empty string |
Beta Was this translation helpful? Give feedback.
-
How are you building your query perhaps? If you are passing the query as a raw string; like: var count int
_, err := db.Model((*Book)(nil)).QueryOne(pg.Scan(&count), `
SELECT count(*)
FROM ?TableName AS ?TableAlias
`) Where the query is not built by pg; then formatter/unformatted query I don't think will return anything. Instead the query string is stored like this: switch query := event.Query.(type) {
case string:
query = strings.TrimSpace(query)
query = strings.ReplaceAll(query, "\n", " ")
... Where the query itself is actually on You can seen an example of this here: https://github.com/monetr/monetr/blob/d121b42b21631c47ad6d03067a241e68667777f9/pkg/logging/pg.go#L44-L130 Where I'm using the after hook to log the query and some other metrics for Sentry. |
Beta Was this translation helpful? Give feedback.
-
My code is as follows: DB_USER, DB_PASSWORD := os.Getenv("POSTGRES_USER"), os.Getenv("POSTGRES_PASS")
if DB_USER == "" && DB_PASSWORD == "" {
DB_USER = "postgres"
DB_PASSWORD = "12345678"
}
db := pg.Connect(&pg.Options{
User: DB_USER,
Password: DB_PASSWORD,
})
defer db.Close()
var student []Student
_, err := db.Query(&student, `SELECT * FROM student`)
_, err = db.Query(&stu, `SELECT * FROM student WHERE Rollno = ?`, 1) I also tried the above link but queryType is coming UNKNOWN. |
Beta Was this translation helpful? Give feedback.
-
How are you binding the query hooks? I can also post a more thorough example using the code you included this evening. |
Beta Was this translation helpful? Give feedback.
-
Thanks for given solution. Now I get querys. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I tried to get query field from struct QueryEvent using of method UnformattedQuery() or FormattedQuery(), but I didnot get any solution for this. Any solution ??
Beta Was this translation helpful? Give feedback.
All reactions