New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Allow LET & RETURN in subqueries aka allow subqueries with full semantics
#1319
Comments
|
4️⃣ There is 4th scenario as well CREATE metrics CONTENT (
LET $sales = (SELECT quantity FROM sales);
RETURN { sales: $sales }
){
"code": 400,
"details": "Request problems detected",
"description": "There is a problem with your request. Refer to the documentation for further information.",
"information": "There was a problem with the database: Parse error on line 1 at character 15 when parsing 'CONTENT (\n LET $sales = (SELECT quantity FROM sales);\n RETURN { sales: $sales }\n)'"
} |
LET & RETURN in subqueries aka allow complex subqueriesLET & RETURN in subqueries aka allow subqueries with full semantics
|
My thoughts:
Syntax
Parser should be something like (NOTE: I know that this is not the exact rust-syntax but I think this gives a good idea) tuple(
tag("{"),
alt(
tuple(value, opt(tag(';'))),
tuple(
statementsWithoutDefine,
opt(tuple(tag(';'), value, opt(tag(';'))))
)
),
tag("}")
) |
What's the issue with DEFINE EVENT define_event ON event WHEN $event = 'CREATE' OR $event = 'UPDATE' THEN (function($value) {
const value = arguments[0]
return await surrealdb.query(`DEFINE EVENT ${value.name} ON ${value.table} WHEN ${value.condition} THEN (${value.statement})`)
});
CREATE event SET name = "foo_event", table = "foo", condition = "$event = 'CREATE'", statement = "CREATE bar SET x = 1"; |
Is your feature request related to a problem?
Essentially, I'm trying to fit my project onto Surreal from the perspective of "Surreal as a Backend" where with the power of Surreal, we could handle all data operations in Surreal without the need of any intermediate layer.
Today we tried to set up events with rich expressions, fields with rich expressions and use rich expressions in
CREATE/UPDATE, but were faced with parse errors.1️⃣
DEFINE EVENT .. WHEN @expression THEN @expression- does not allowLETin either of@expression{ "code": 400, "details": "Request problems detected", "description": "There is a problem with your request. Refer to the documentation for further information.", "information": "There was a problem with the database: Parse error on line 1 at character 0 when parsing 'DEFINE EVENT update_metrics ON TABLE forecast WHEN $event = \"CREATE\" THEN (\n LET $sales = (SELECT'" }2️⃣
DEFINE FIELD ... VALUE @expressiondoes not allowLETin@expression{ "code": 400, "details": "Request problems detected", "description": "There is a problem with your request. Refer to the documentation for further information.", "information": "There was a problem with the database: Parse error on line 1 at character 38 when parsing 'VALUE (\n LET $sales = (SELECT quantity FROM sales);\n LET $total = math::sum($sales);\n LET $'" }3️⃣
CREATE ... SET @field = @valuedoes not allowLETin@value{ "code": 400, "details": "Request problems detected", "description": "There is a problem with your request. Refer to the documentation for further information.", "information": "There was a problem with the database: Parse error on line 1 at character 15 when parsing 'SET average_sales = (\n LET $sales = (SELECT quantity FROM sales);\n LET $total = math::sum($sal'" }Describe the solution
Wherever a subquery can be used as an expression, allow using the full SRQL power there.
Alternative methods
An intermediate API layer would definitely work.
But I think that Surreal is closer to being a complete CRUD layer on it's own than what it's worth to build an intermediate layer around it.
SurrealDB version
surreal 1.0.0-beta.8+20220930.c246533 for macos on aarch64
Contact Details
@tomsseisums
Is there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: