Raw queries #1876
-
Just a quick question/suggestion. Well, I have an app which uses go-pg mainly. It looks nice and sound, but I have to do some raw queries with variable results. The use-case could be described like this: "advanced version of raw SQL API" (hasura or any existing BI or ETL solution did not fit the needs damn). So, input is predictable in one way or another, the query will be quite complex (CTEs, window-functions, sub-queries, complex joins). The output (columns) is kind of predictable, but not really. In general, it is easy to implement with low-level drivers by making the iteration and scanning each row into the map, interface{} or just a slice of strings. It will allow to stream the data, make less noise in the code, great flexibility. It is easily doable with database/sql, but might not be that easy with go-pg. I would like to avoid keeping two separate database drivers, keeping 2 db pools. So, here are the pitfalls I found:
Well, not a requirement, just another usecase, it would be awesome to have some flexibility. I believe go-pg is quite flexible right now, but it might not be as obvious as should be. Anyway, wanted to give you some feedback asap, hope it helps you, might help me if you will suggest the preferred approach :) Btw, we redid the otel tracing hook almost from the zero, to be compliant with the specs, will send you PR on weekends as well. There are a couple of issues and some optimizations still to be done, but the current otel tracing hook has some critical issues and missing essential data, we'll see |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Not to say that this is the best solution, but it might be a solution. What about making a model for that query and then making the query a view in SQL? Then go-pg would simply select from that view as if it were a table allowing you to use your |
Beta Was this translation helpful? Give feedback.
-
Questions like this is one of the reasons I've created Bun. It works on top of database/sql so |
Beta Was this translation helpful? Give feedback.
Questions like this is one of the reasons I've created Bun. It works on top of database/sql so
sql.Rows
is always available.