| name | generate-sql-route |
| description | Create a pREST custom SQL template route under /_QUERIES. Use when the user needs a parameterized SQL script with curl examples. |
Generate SQL template route
When to use
- User has a SQL query that should become a REST endpoint
- User asks for a custom report or filtered read via pREST
- User needs verb-specific templates (read/write/update/delete)
Ask first
- HTTP verb (default GET / read)
- Folder and script name (e.g.
reports / users)
- Query parameters and types
- Target schema/table(s)
- Single-DB vs multi-DB alias prefix
- Path to
queries.location if already configured
Instructions
- Place scripts under the configured queries directory:
queries/
└── <folder>/
└── <name>.read.sql # GET
└── <name>.write.sql # POST
└── <name>.update.sql # PUT/PATCH
└── <name>.delete.sql # DELETE
- Use template params as
{{.field}}. Prefer helpers when useful (isSet, defaultOrValue, inFormat, limitOffset).
- Ensure
prest.toml includes:
[queries]
location = "./queries"
- Document the real URL shape (never invent
/reports/users/:id):
GET /_QUERIES/<folder>/<name>?field=value
GET /_QUERIES/<database>/<folder>/<name>?field=value
- Include curl examples and a sample JSON response.
- Note that template parameters are sanitized in current pREST mainline — still warn against injecting raw SQL fragments via params.
Safety notes to include
- Prefer parameterized filters over
SELECT * without limits.
- Restrict which roles can call write/update/delete scripts.
- Avoid destructive scripts unless explicitly requested.
- Call out that custom queries bypass table ACL patterns differently than CRUD table endpoints — keep them least-privilege.
Docs
https://docs.prestd.com/api-reference/custom-queries