Custom Queries
If you need to perform an advanced SQL, you can write some scripts SQL and access them by REST. These scripts are templates where you can pass by URL and values to them.
awesome_folder/example_of_powerful.read.sql:
Get result:
To activate it, you need to configure a location to scripts in your prest.toml
like:
Scripts templates rules
In your scripts, the fields to replace have to look like: field1 or field2 are examples.
Script file must have a suffix based on http verb:
GET
.read.sql
POST
.write.sql
PUT, PATCH
.update.sql
DELETE
.delete.sql
In queries.location
You need to have a folder for your scripts:
Template data
You can access the query parameters of the incoming HTTP request using the .
notation.
For instance, the following request:
Makes it available the fields field1
and field2
In the script:
You can also access the query headers of the incoming HTTP requests using the .header
notation.
For instance, the following request:
makes available the headers X-UserId
and X-Application
in the script:
Template functions
isSet
Return true if the param is set.
defaultOrValue
Return param value or default value.
inFormat
If you need to format data for usage on a IN ('option1', 'option2')
statement. You can use this with the field inside the format. Whenever passing multiple arguments to inFormat
function, you must use multiple field1
instances on the URL.
For example: I want to query the field name
with options Mary
and John
.
Future updates will include the support of multiple strings split by ,
on the same instance of the field.
split
Splits a string into substrings separated by a delimiter
limitOffset
Assemble limit offset()
string with validation for non-allowed characters parameters must be integer values
generating the query:
We recommend using the default pREST variables _page
and _page_size
:
Ready-made queries
consultations ready to use prest
Last updated