-
I've been trying to make a function that creates users with no success today. function create_user(nickname: str, email: str, pass: bytes) -> optional User
{
volatility := 'VOLATILE';
using EdgeQL $$
WITH
MODULE DEFAULT
conflicting := (
SELECT User {
created_at,
}
FILTER .nickname = nickname OR .email = email
LIMIT 2
),
deleted := (
FOR x IN conflicting
UNION (
DELETE
x
IF
NOT .email_verified
AND (datetime_of_transaction() - .created_at) > to_duration(hours := 24 * 5)
ELSE
<User>{}
)
)
SELECT (
(INSERT User {
nickname := nickname,
email := email,
password := password,
})
IF
len(deleted) = len(conflicting)
ELSE
<User>{}
)
$$;
}; Explanation:
The code I have so far does not work for multiple reasons
Is this function possible with current state of edegql and edgedb or I should wait for EdgePL? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You must use a set literal in
|
Beta Was this translation helpful? Give feedback.
-
After a few recent bugfixes I was able to test new approach using this #684 (comment) hack, but I still have 1 more issue: nothing is ever returned from function.
Did I make some obvious mistake here? My tests in REPL successfully return user:
I created a gist with simplified schema: https://gist.github.com/Fogapod/0ad0763be7e90e6ab46cb49325e54eab |
Beta Was this translation helpful? Give feedback.
You must use a set literal in
FOR
, so the correct syntax is: