Skip to content

Commit

Permalink
make use of optional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Quin Lynch committed Apr 17, 2024
1 parent b942a6b commit 2bc986f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 30 deletions.
25 changes: 0 additions & 25 deletions examples/EdgeDB.Examples.CSharp/Examples/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,6 @@ public async Task ExecuteAsync(EdgeDBClient client)
{
try
{
var friend = new Person {Name = "ABC", Email = "123"};
var ext1 = "HIJ";

var test = await QueryBuilder
.With(ctx => new
{
Friend = ctx.SubQuerySingle(
QueryBuilder.Select<Person>().Filter(x => x.Email == friend.Email)
)
})
.Insert(ctx => new Person
{
BestFriend = ctx.Variables.Friend,
Name = "DEF",
Email = "456"
})
.UnlessConflict()
.Else(qb => qb
.Update<Person>()
.Set(shape => shape
.Set(x => x.Name, _ => ext1)
)
)
.CompileAsync(client, true);

await QueryBuilderDemo(client);
}
catch (Exception x)

Check warning on line 39 in examples/EdgeDB.Examples.CSharp/Examples/QueryBuilder.cs

View workflow job for this annotation

GitHub Actions / Run test suite

The variable 'x' is declared but never used

Check warning on line 39 in examples/EdgeDB.Examples.CSharp/Examples/QueryBuilder.cs

View workflow job for this annotation

GitHub Actions / Run test suite

The variable 'x' is declared but never used
Expand Down
4 changes: 2 additions & 2 deletions src/EdgeDB.Net.QueryBuilder/Grammar/Terms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ public static QueryWriter Function(this QueryWriter writer, string name, params
public static QueryWriter SingleQuoted(this QueryWriter writer, Value value)
=> writer.Append('\'', value, '\'');

public static QueryWriter QueryArgument(this QueryWriter writer, Value type, Value name, Deferrable<string>? debug = null)
=> writer.Marker(MarkerType.Variable, $"variable_{name}", debug, '<', type, ">$", name);
public static QueryWriter QueryArgument(this QueryWriter writer, Value type, Value name, Deferrable<string>? debug = null, bool optional = false)
=> writer.Marker(MarkerType.Variable, $"variable_{name}", debug, optional ? "<optional " : "<", type, ">$", name);

public static Value[] Span(this QueryWriter writer, WriterProxy proxy)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EdgeDB.Net.QueryBuilder/Lexical/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public bool TryProxy(

using var nodeObserver = new RangeNodeObserver(writer);
_callback(writer);

first = nodeObserver.First;
last = nodeObserver.Last;
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/EdgeDB.Net.QueryBuilder/QueryNodes/InsertNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private ShapeDefinition BuildInsertShape(Type? shapeType = null, Union<LambdaExp
writer
.Append(property.EdgeDBName)
.Append(" := ")
.QueryArgument(new(edgeqlType), varName);
.QueryArgument(new(edgeqlType), varName, optional: !edgedbProp.Required);
}));
continue;
}
Expand All @@ -410,7 +410,7 @@ private ShapeDefinition BuildInsertShape(Type? shapeType = null, Union<LambdaExp
setters.Add(new ShapeSetter(writer => writer
.Append(property.EdgeDBName)
.Append(" := ")
.QueryArgument(new(edgeqlType), varName)
.QueryArgument(new(edgeqlType), varName, optional: value is null)
));
continue;
}
Expand Down

0 comments on commit 2bc986f

Please sign in to comment.