Blueprints
CRUD operations in SurrealQL: run multiple SurrealDB queries and send the query results via Slack
Source
yaml
id: surreal-db-slack
namespace: company.team
tasks:
- id: company
type: io.kestra.plugin.surrealdb.Query
query: |
CREATE company SET
name = 'Kestra',
created_at = time::now()
- id: delete_anna
type: io.kestra.plugin.surrealdb.Query
query: DELETE author:anna;
- id: add_author_tbl
type: io.kestra.plugin.surrealdb.Query
disabled: true
query: |
CREATE author:anna SET
name.first = 'Anna',
name.last = 'Geller',
name.full = string::join(' ', name.first, name.last),
admin = true
- id: fix_admin_permission
type: io.kestra.plugin.surrealdb.Query
query: UPDATE author:anna SET admin = false WHERE name.last = 'Geller';
- id: create_article_tbl
type: io.kestra.plugin.surrealdb.Query
query: >
CREATE article SET created_at = time::now(), author = author:anna, title =
'Kestra 0.12 simplifies building modular, event-driven and containerized
workflows', company = (SELECT VALUE id FROM company WHERE name = 'Kestra'
LIMIT 1)[0]
- id: query
type: io.kestra.plugin.surrealdb.Query
query: SELECT title FROM article;
fetchType: FETCH_ONE
- id: log_query_results
type: io.kestra.plugin.core.log.Log
message: "{{ outputs.query.row }}"
- id: slack
type: io.kestra.plugin.notifications.slack.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"channel": "#general",
"text": "{{ outputs.query.row.title }}"
}
pluginDefaults:
- type: io.kestra.plugin.surrealdb.Query
values:
host: localhost
database: test
namespace: test
username: root
password: root
About this blueprint
This flow demonstrates how to use SurrealDB to run queries, create tables, as well as insert, update and delete data. The flow parses the final query result and sends it in a Slack message.
This flow assumes that the Slack Incoming Webhook URL is stored as a secret named SLACK_WEBHOOK
.