ctx.sql provides SQL execution and management. It is commonly used in RunJS (e.g. JSBlock) to access the database directly. It supports temporary SQL execution, executing saved SQL templates by ID, binding parameters, result type control, and saving/deleting SQL templates.
runById (run saved SQL templates by ID).run, save, destroy (execute temporary SQL, save/update/delete templates).Therefore, frontend logic for logged-in users can use ctx.sql.runById(uid, options). For dynamic SQL or template management, ensure the current role has SQL config permissions.
Note: implementation lives in FlowSQLRepository. Only commonly used methods/params are listed here.
| Method | Description | Permission |
|---|---|---|
ctx.sql.run(sql, options?) | Execute temporary SQL with bind and result type | Requires SQL config permission |
ctx.sql.save({ uid, sql, dataSourceKey? }) | Save/update SQL template by ID | Requires SQL config permission |
ctx.sql.runById(uid, options?) | Run saved SQL template by ID (options same as run) | Logged-in users |
ctx.sql.destroy(uid) | Delete SQL template by ID | Requires SQL config permission |
Options for run / runById
bind: bind variables (object or array)type: result type (e.g. select multiple rows, selectRow single row, selectVar single value, raw)dataSourceKey: data source keyfilter: filter (if supported by the API)Options for save
uid: template unique ID, used by runById(uid, ...)sql: SQL contentdataSourceKey: optional data source key