Comments (1)
I realize that there needs to be clarification on how this would work with transactions.
Transactions in their current state are pretty convoluted. They only work at the top-level and provide no warning about this when used in lower scopes.
For example, the following doesn't work as expected:
{
BEGIN;
CREATE foo SET bar = "biz";
CANCEL;
}
The expected result would be that the CREATE
statement doesn't commit because of the CANCEL
, but when executed we see that it does create a new record, and that the BEGIN
/CANCEL
/COMMIT
statements have no apparent effect.
Anyways, the problem at hand is how RETURN
statements change the result of a transaction. If returns break execution, it wouldn't allow calling COMMIT
or CANCEL
and getting a result.
IMO, the most intuitive solution is to make transactions work in blocks and make RETURN
act like a CANCEL
that breaks execution.
A couple examples:
BEGIN;
CREATE foo SET bar = "biz";
RETURN CREATE foo SET bar = "boo";
# This RETURN does nothing (unlike before, where it would make it the single return value of the transaction
COMMIT;
Result:
[
[{id:"foo:f09uja09sdj0asd", bar:"biz"}],
[{id:"foo:adsad0h80jfe09j", bar:"boo"}]
]
{
BEGIN;
CREATE foo SET bar = "biz";
RETURN CREATE foo SET bar = "boo"; # Here, the RETURN cancels the transaction and returns the CREATE
COMMIT; # This block doesn't return a value
}
Result:
[
[{id:"foo:adsad0h80jfe09j", bar:"boo"}]
]
{
BEGIN;
CREATE foo SET bar = "biz";
CREATE foo SET bar = "boo";
COMMIT;
true # the block returns true
}
Result: [true]
Edge cases:
What if a later statement depends on the result of a statement inside a canceled transaction?
This is currently covered:
BEGIN;
LET $foo = CREATE foo SET bar = "biz";
CANCEL;
RETURN $foo;
$foo
produces a phantom result, a record that never existed and is worthless outside of the canceled transaction. To me, this represent the biggest flaw of this syntax: the transaction has a scope that is not expressed, but is instead merged into the current scope.
An improved syntax would be explicit about the scope:
BEGIN {
LET $foo = CREATE foo SET bar = "biz";
CANCEL false; # an optional return parameter
$foo
}
Here, the scope is explicit and variables are not leaked outside. It also allows for an implicit commit as the final value. CANCEL
and COMMIT
would have an optional return value for setting the value of the transaction.
Anyways, I guess this does warrant an RFC considering how many breaking changes would be needed.
from surrealdb.
Related Issues (20)
- Bug: Random record IDs provide less than 128 bits of randomness HOT 1
- Feature: Better EXPLAIN Details and Statistics
- Add REMOVE TABLE foo IF EXIST HOT 2
- Feature: Limit outgoing connections to certain hosts by Root, NS and DB HOT 3
- Bug: Edge inserted via INSERT cannot be queried with -> HOT 2
- Bug: (Rust Driver) Serializing trait objects using `typetag` crate fails HOT 2
- Bug: non-conforming fields are silently deleted
- Feature: Add more functions for supporting semver strings HOT 1
- Feature: Raise an error when query parameters are missing HOT 2
- Bug: Live query inconsistent behaviour HOT 3
- Feature: Searching through array of string or object
- Feature: Is there a feature to unnest array into rows ?
- Feature: Custom tokenizer and custom filter using function HOT 2
- Bug: multi-column unique index not ignoring 'NONE` values
- Feature: Vue-like reactivity: computed properties HOT 1
- Bug: SELECTing from relations returns only 1 record HOT 2
- Feature: Query nested field just like json_path_query in Postgres HOT 3
- Bug: Unexpected behaviour of serialization/deserialization for IpAddr object. HOT 3
- Bug: MacOS brew upgrade surrealdb doesn't upgrade to 1.0.2 or 1.1.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surrealdb.