sqlf icon indicating copy to clipboard operation
sqlf copied to clipboard

Add a Render() function which returns a valid query

Open chrismwendt opened this issue 3 years ago • 1 comments
trafficstars

Check this out:

q := sqlf.Sprintf("SELECT * FROM repos WHERE name = $1", "github.com/keegancsmith/sqlf")
fmt.Println(q.Render(sqlf.PostgresBindVar))

That prints this:

SELECT * FROM repos WHERE name = 'github.com/keegancsmith/sqlf'

Ready to copy-n-paste into psql, or EXPLAIN ANALYZE .... and print the timing info for local dev.

CleanShot 2022-02-15 at 03 51 57@2x

This was the bare minimum necessary to work for my pursposes, but there's a lot left to do in order to work in general for all BindVars, drivers, and argument types.

chrismwendt avatar Feb 15 '22 10:02 chrismwendt

I've been using this locally behind a debug flag while working on Rockskip. I'm not 100% sure the escape function is safe (so I removed the code that ran the query automatically).

I didn't expect this to get merged without a lot more work, and it should've been a draft to begin with.

chrismwendt avatar Feb 16 '22 02:02 chrismwendt