Resquel lets you publish SQL queries as GlobalForms web addresses (routes). Forms call these addresses to load data, for example to fill a Select list or look up a customer by ID. Each route runs a query you define, and values from the request are passed to the query safely as parameters.
PostgreSQL support and route tokens require GlobalForms version 10.7.1 or greater.
Supported databases
|
Database |
|
|---|---|
|
Microsoft SQL Server |
|
|
MySQL or MariaDB |
|
|
PostgreSQL |
|
Configure Resquel
Add a resquel section under settings in config\local.json, then restart the GlobalForms service:
{
"settings": {
"resquel": {
"type": "mssql",
"db": {
"server": "sql-server",
"port": 1433,
"database": "CompanyDB",
"user": "svc_globalforms",
"password": "<Password>",
"requestTimeout": 30000
},
"routes": [
{
"method": "get",
"endpoint": "/departments",
"query": "SELECT DeptCode, DeptName FROM Departments ORDER BY DeptName;"
}
]
}
}
}
Connection settings (db)
|
Setting |
Description |
|---|---|
|
|
Database server name or address. For a named SQL Server instance, use |
|
|
1433 (SQL Server), 3306 (MySQL), 5432 (PostgreSQL) |
|
|
The database queries run against |
|
|
A database account with only the permissions the routes need |
|
|
Milliseconds to wait for a query (default 30000) |
|
|
SQL Server only. Use encrypted connections; trust a self-signed server certificate. |
|
|
PostgreSQL only. Set to |
Route settings (routes)
|
Setting |
Description |
|---|---|
|
|
|
|
|
The route's address, unique across routes, for example |
|
|
The SQL to run. Test it in your database tool first. |
|
|
Optional. A list of access tokens; callers must provide one. See Route tokens. |
A route is available at your GlobalForms address plus the endpoint, for example https://forms.example.com/departments. Open it in a browser to check that it returns data. Results are returned in a rows list.
Pass values to a query
Use {{ }} to insert a value from the request:
|
Placeholder |
Value from |
Example |
|---|---|---|
|
|
A |
|
|
|
A |
|
{
"method": "get",
"endpoint": "/customers/:id",
"query": "SELECT CustomerName, CustomerContact FROM Customers WHERE CustomerID = {{ params.id }};"
}
Do not put quotes around {{ }} placeholders, even for text values. Each placeholder is sent to the database as a parameter, which already handles text correctly and protects against SQL injection. Write WHERE Make = {{ params.make }}, not WHERE Make = '{{ params.make }}'.
For a partial text match, join the wildcards in SQL. For SQL Server: WHERE Name LIKE '%' + {{ query.q }} + '%'. Queries written in the older '%{{ query.q }}%' style are converted automatically when GlobalForms starts.
Route tokens
To require a token for a route, add a tokens list:
{
"method": "get",
"endpoint": "/customers/:id",
"tokens": ["<long random token>"],
"query": "SELECT CustomerName FROM Customers WHERE CustomerID = {{ params.id }};"
}
Callers must send a matching token in an x-api-token header or a token= value in the address. Requests without a valid token are refused with 403 Forbidden.
A token used in a form's Select URL is visible to anyone who can open that form. Tokens keep out callers who don't have the form, but they are not a substitute for limiting what each query returns. See Securing Your SQL Data Lookups.
Troubleshooting
|
Symptom |
Cause and fix |
|---|---|
|
The route address returns "not found" |
Check the |
|
Cannot connect to the database |
Check the server, port and firewall. For SQL Server, check that TCP/IP is enabled and, for named instances, that the SQL Server Browser service is running. |
|
Login failed |
Check the user and password, and that SQL Server allows SQL Server authentication. |
|
Query errors, or no results when filtering by text |
Remove any quotes around |
|
|
The route has |