pglite
pglite copied to clipboard
feat: SQL template API
Adds the sql template API that under the hood uses methods from the pglite/template export to parametrize a templated query and then run PGlite.query.
The template export has the following methods:
querywhich "executes" the template and replaces all values with parameter placeholders and returns{ query: string, params: any[] }for running a parametrized queryidentifierwhich escapes identifiers and prevents parametrizationrawwhich only prevents parametrization - allows regular string templating basicallysqlwhich allows nesting SQL templated strings and creating custom utilities (to avoid exploding in complexity ourselves)
I've added docstrings with examples on all of them - if we're happy with the API I can add the docs to this PR as well.
Added basic test coverage for the utilities outside of PG and basic coverage of just using the API instead of the db.query one.
Built bundles:
- Postgres WASM: https://github.com/electric-sql/pglite/actions/runs/10493033965/artifacts/1838150102
- Interim build files: https://github.com/electric-sql/pglite/actions/runs/10493033965/artifacts/1838150333
- PGlite: https://github.com/electric-sql/pglite/actions/runs/10493033965/artifacts/1838176881
- Demos: https://github.com/electric-sql/pglite/actions/runs/10493033965/artifacts/1838190001
🚀 Deployed on https://66c60c69685e0525373cc309--pglite.netlify.app
@samwillis added it to the transaction interface as well - no tests for it though 👀
SO timely! TinyBase plugin coming as soon as this ships.