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 FUNCTION statement
The ALTER FUNCTION statement can be used to modify an existing defined function.
Statement syntax
SurrealQL Syntax
ALTER FUNCTION [ IF EXISTS ] fn::@name
[ ( [ $argument: @type, ... ] ) ] [ -> @type | DROP RETURNS ]
[ { @query ... } ]
[ COMMENT @string | DROP COMMENT ]
[ PERMISSIONS [ NONE | FULL | WHERE @condition ] ]
export const alterAst = { type: "Diagram", padding: [10, 20, 10, 20], children: [ { type: "Sequence", children: [ { type: "Terminal", text: "ALTER FUNCTION" }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "IF" }, { type: "Terminal", text: "EXISTS" }, ], }, }, { type: "Terminal", text: "fn::@name" }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "(" }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Sequence", children: [ { type: "Terminal", text: "$argument" }, { type: "Terminal", text: ":" }, { type: "Terminal", text: "@type" }, ], }, { type: "ZeroOrMore", child: { type: "Sequence", children: [ { type: "Terminal", text: "," }, { type: "Terminal", text: "$argument" }, { type: "Terminal", text: ":" }, { type: "Terminal", text: "@type" }, ], }, repeat: { type: "Skip" }, }, ], }, }, { type: "Terminal", text: ")" }, ], }, }, { type: "Optional", child: { type: "Choice", index: 0, children: [ { type: "Sequence", children: [ { type: "Terminal", text: "->" }, { type: "Terminal", text: "@type" }, ], }, { type: "Sequence", children: [ { type: "Terminal", text: "DROP" }, { type: "Terminal", text: "RETURNS" }, ], }, ], }, }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "{" }, { type: "NonTerminal", text: "@query" }, { type: "Terminal", text: "..." }, { type: "Terminal", text: "}" }, ], }, }, { 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" }, ], }, ], }, }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "PERMISSIONS" }, { type: "Choice", index: 1, children: [ { type: "Terminal", text: "NONE" }, { type: "Terminal", text: "FULL" }, { type: "Sequence", children: [ { type: "Terminal", text: "WHERE" }, { type: "NonTerminal", text: "@condition" }, ], }, ], }, ], }, }, ], }, ], };
Example usage
-- Declare a function
DEFINE FUNCTION fn::get_message($input: any) {
$input.message
};
-- No `message` field, returns nothing
fn::get_message("wrong input");
-- Tighten up the valid input for the function
ALTER FUNCTION fn::get_message($input: { error_code: 200, message: string } | {error_code: 404, message: string} ) {
$input.message
};
-- Returns an error now
fn::get_message("wrong input");
-- Okay, returns 'Looks good'
fn::get_message({ error_code: 200, message: "Looks good" });