quinchs / EdgeDB.Net

C# edgedb client
Apache License 2.0
45 stars 3 forks source link

Complex objects in WITH statements #27

Closed quinchs closed 1 year ago

quinchs commented 1 year ago

Summary

With the insane power of using json within the edgeql standard library, we can allow any arbitrary object to be included in a WITH statement and access any property on it using json.

Example

var data = new { Name = "example", Email = "example@example.com" };

QueryBuilder
    .With(new { MyObject = EdgeQL.AsJson(data) })
    .Insert(ctx => new Person { Name = ctx.Variables.MyObject.Value.Name, Email = ctx.Variables.MyObject.Value.Email});

The Member translator can be adapted to add json_get paths for any occurrence of IJsonVariable (returned from EdgeQL.AsJson) allowing ease of use with complex parameters within WITH blocks.