edgedb / edgedb-net

The official .NET client library for EdgeDB
https://edgedb.com
Apache License 2.0
82 stars 9 forks source link

EdgeQLSyntaxError: Unexpected '+=' #8

Closed quinchs closed 2 years ago

quinchs commented 2 years ago

Summary

Seems like the member init translator has decided to break the EdgeQL syntax rules again.. 🤷🏻

Standard libs funcs with contextual assignment operators (+=, -=, etc) NEED to preserve their set operators, which when I rewrote the init translator, got left out of the new link path.

Exception

EdgeQLSyntaxError: Unexpected '+='
EdgeQLSyntaxError: Unexpected '+='
   |
 1 | with BMVZTQOFIRIR := (insert UserSchema { created_at := <datetime>$DCDLEUGSEZHB, schema := <str>$FDBHZNBORAEF }) update User filter .user_id ?= <int64>$SZUBJXNCKYMM set { schema_history := += BMVZTQOFIRIR }
   |                                                                                                                                                                                              ^^

QueryBuilder code:

await QueryBuilder
    .Update<User>(old => new User
    {
        // this line here!
        SchemaHistory = EdgeQL.AddLink(QueryBuilder.Insert(migration, false))
    })
    .Filter(x => x.UserId == id)
    .ExecuteAsync(_edgedb, token: token);
quinchs commented 2 years ago

Also- Maybe we should add a more DX-appealing approach to adding a multi link value rather than a STDLib func without having to make the user wrap a custom type for link properties...

Achieving this might come in IL parsing as we can use Func<T> instead of expressions, allowing for this kind of API

await QueryBuilder
    .Update<User>(user=>
    {
        user.SchemaHistory.Add(QueryBuilder.Insert(migration, false))
    })
    .Filter(x => x.UserId == id)
    .ExecuteAsync(_edgedb, token: token);

Where the Add method can be an extension method:

public static void Add<TCollection, TQueryElement>(this TCollection col, IQuery<TQueryElement> query)
    where TCollection : IEnumerable<TQueryElement>
{
    // impl
}

Ah the possibilities of parsing machine code, maybe the dotnet team can update the Expression api to be more feature complete? in either case IL parsing is on the todo so this should be ultimately resolved once the parser is written and Func<T> is the norm