import Since from '@components/shared/Since.astro' import RailroadDiagram from '@components/RailroadDiagram.astro' import Tabs from '@components/Tabs/Tabs.astro' import TabItem from '@components/Tabs/TabItem.astro'
ALTER EVENT statement
The ALTER EVENT statement can be used to modify an existing defined event.
Statement syntax
SurrealQL Syntax
ALTER EVENT [ IF EXISTS ] @name ON [ TABLE ] @table
[ ASYNC [ RETRY @retry ] [ MAXDEPTH @max_depth ] | DROP ASYNC ]
[ WHEN @condition | DROP WHEN ]
[ THEN @action, ... | DROP THEN ]
[ COMMENT @string | DROP COMMENT ]
export const alterAst = { type: "Diagram", padding: [10, 20, 10, 20], children: [ { type: "Sequence", children: [ { type: "Terminal", text: "ALTER EVENT" }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "IF" }, { type: "Terminal", text: "EXISTS" }, ], }, }, { type: "Terminal", text: "@name" }, { type: "Terminal", text: "ON" }, { type: "Optional", child: { type: "Terminal", text: "TABLE" }, }, { type: "Terminal", text: "@table" }, { type: "Optional", child: { type: "Choice", index: 0, children: [ { type: "Sequence", children: [ { type: "Terminal", text: "ASYNC" }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "RETRY" }, { type: "NonTerminal", text: "@retry" }, ], }, }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "MAXDEPTH" }, { type: "NonTerminal", text: "@max_depth" }, ], }, }, ], }, { type: "Sequence", children: [ { type: "Terminal", text: "DROP" }, { type: "Terminal", text: "ASYNC" }, ], }, ], }, }, { type: "Optional", child: { type: "Choice", index: 0, children: [ { type: "Sequence", children: [ { type: "Terminal", text: "WHEN" }, { type: "NonTerminal", text: "@condition" }, ], }, { type: "Sequence", children: [ { type: "Terminal", text: "DROP" }, { type: "Terminal", text: "WHEN" }, ], }, ], }, }, { type: "Optional", child: { type: "Choice", index: 0, children: [ { type: "Sequence", children: [ { type: "Terminal", text: "THEN" }, { type: "NonTerminal", text: "@action" }, { type: "ZeroOrMore", child: { type: "Sequence", children: [ { type: "Terminal", text: "," }, { type: "NonTerminal", text: "@action" }, ], }, repeat: { type: "Skip" }, }, ], }, { type: "Sequence", children: [ { type: "Terminal", text: "DROP" }, { type: "Terminal", text: "THEN" }, ], }, ], }, }, { type: "Optional", child: { type: "Choice", index: 0, children: [ { type: "Sequence", children: [ { type: "Terminal", text: "COMMENT" }, { type: "Terminal", text: "@string" }, ], }, { type: "Sequence", children: [ { type: "Terminal", text: "DROP" }, { type: "Terminal", text: "COMMENT" }, ], }, ], }, }, ], }, ], };
Example usage
-- Define an event
DEFINE EVENT publish_post ON TABLE post
WHEN $event = "CREATE"
THEN (
UPDATE post SET status = "PUBLISHED" WHERE id = $after.post_id
);
-- Make it async
ALTER EVENT publish_post ON TABLE post ASYNC;