jet icon indicating copy to clipboard operation
jet copied to clipboard

Print Full SQL Instead of PreparedStatement

Open driverpt opened this issue 2 years ago • 7 comments

Is your feature request related to a problem? Please describe. Currently we are using RDS Data API which has a very specific way of doing queries (Doesn't support ? character).

We required to either have named placeholders (each prefixed by :) and typed arguments, or we just call ExecuteStatement with the fully generated and escaped SQL.

Connecting directly via Connection String is not an option because we are using AWS Lambda.

Source

Describe the solution you'd like A .RawSql() Function that prints the whole SQL

driverpt avatar Mar 25 '22 18:03 driverpt

Hi @driverpt. .DebugSql() will return SQL without parameters.

go-jet avatar Mar 26 '22 11:03 go-jet

Will it he pretty printed? I'm asking because some of the queries are a bit big and there is a 1 MB Limit

driverpt avatar Mar 26 '22 11:03 driverpt

DebugSql will return valid sql. You can see sample here or in tests.

But, note that DebugSql is not intended to be used on the production, because of the possible SQL injection attacks. If I were you, I would probably use .Sql() and replace each occurrence of ? with some generated name :gen_name in the query.

go-jet avatar Mar 26 '22 12:03 go-jet

We could do what, but wouldn't it be a bit costly in long queries?

AWS RDS Data Api is nice, but it requires a lot of custom code.

Is there some way of creating a custom adapter for JET? To generate the query to Execute Statement Endpoint?

driverpt avatar Mar 26 '22 14:03 driverpt

How big are the queries? 1MB?

You can also fork the repo and update ArgumentPlaceholder function -
return ":var_" + strconv.Itoa(ord). Or maybe update the code so that this function can be updated on startup.

Is there some way of creating a custom adapter for JET? To generate the query to Execute Statement Endpoint?

Not sure what you mean? Do you mean adapter for query generation (.Sql())? Should be answered with above comment. Or do you mean do adapt .Exec or .Query methods? No, there is no such possibility.

go-jet avatar Mar 26 '22 18:03 go-jet

Can you make these configurable when we're initializing Jet?

Can you modify the ArgumentPlaceholder Function to also receive the Parameter Name ?

Thanks in advance

driverpt avatar Mar 26 '22 18:03 driverpt

I think it is the best, for you to fork the project and make necessary changes. Additional changes will probably be needed, because this data source is not supported currently.

go-jet avatar Mar 27 '22 08:03 go-jet