quinchs / EdgeDB.Net

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

WITH DX and design #23

Closed quinchs closed 1 year ago

quinchs commented 1 year ago

Summary

The current way we reference values defined in the WITH block is like so:

QueryBuilder
    .With("name", person)
    .Select(ctx => ctx.Global<Person>("name"))

With EdgeDB 2.0, global now references a schema-defined global. This pattern needs to change as the confusion can be clear.

New design

The new design for WITH will use anonymous types[^fn1]. The context variable will make use of this anonymous type allowing a workflow that looks like this:

QueryBuilder
    .With(new { Friend = person })
    .Select(ctx => ctx.Variables.Friend)

The pro about this approach is that ctx.Variables is strongly typed thanks to generics, the name "Variables" is subject to change but it still gets the point across.

For internally defined values within a with block, they will still use the QueryGlobal class to maintain references etc.

[^fn1]: read about anonymous types here