sqlf
sqlf copied to clipboard
Add a Render() function which returns a valid query
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.

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.
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.