From e7a469e17023007249d370abcc9a0ca2aaa14ce6 Mon Sep 17 00:00:00 2001 From: Quin Lynch Date: Tue, 31 Oct 2023 14:12:26 -0300 Subject: [PATCH] fix merge related stuff --- .../Attributes/EdgeDBTypeAttribute.cs | 2 +- .../Info/EdgeDBTypeDeserializerInfo.cs | 10 +-- .../Binary/Builders/TypeBuilder.cs | 2 +- .../Binary/Codecs/ObjectCodec.cs | 2 +- src/EdgeDB.Net.Driver/Binary/PacketReader.cs | 3 + .../Clients/EdgeDBBinaryClient.cs | 14 +-- .../Models/DataTypes/Json.cs | 10 +++ .../Extensions/TypeExtensions.cs | 9 +- src/EdgeDB.Net.QueryBuilder/QueryBuilder.cs | 8 -- .../QueryBuilder/QueryBuilder.With.cs | 15 ++-- .../QueryNodes/InsertNode.cs | 75 ++++++++-------- .../QueryObjectManager.cs | 86 ------------------- .../Expressions/InitializationTranslator.cs | 13 +-- .../Expressions/UnaryExpressionTranslator.cs | 12 +-- .../Utils/QueryGenerationUtils.cs | 5 +- .../EdgeDBQueryProvider.cs | 1 + .../GenericlessQueryBuilder.cs | 15 ++-- .../OperatorGenerator.cs | 8 +- 18 files changed, 97 insertions(+), 193 deletions(-) delete mode 100644 src/EdgeDB.Net.QueryBuilder/QueryObjectManager.cs diff --git a/src/EdgeDB.Net.Driver/Attributes/EdgeDBTypeAttribute.cs b/src/EdgeDB.Net.Driver/Attributes/EdgeDBTypeAttribute.cs index befccd9c..8a945553 100644 --- a/src/EdgeDB.Net.Driver/Attributes/EdgeDBTypeAttribute.cs +++ b/src/EdgeDB.Net.Driver/Attributes/EdgeDBTypeAttribute.cs @@ -3,7 +3,7 @@ /// /// Marks this class or struct as a valid type to use when serializing/deserializing. /// -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] public class EdgeDBTypeAttribute : Attribute { /// diff --git a/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeDeserializerInfo.cs b/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeDeserializerInfo.cs index dd3d4189..5036c0ed 100644 --- a/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeDeserializerInfo.cs +++ b/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeDeserializerInfo.cs @@ -66,7 +66,7 @@ public EdgeDBTypeDeserializeInfo(Type type, TypeDeserializerFactory factory) public string EdgeDBTypeName { get; } - public bool IsAbtractType + public bool IsAbstractType => _type.IsAbstract || _type.IsInterface; public bool RequiresTypeName { get; private set; } @@ -91,10 +91,10 @@ private ObjectActivator? Activator private ObjectActivator? CreateActivator() { - if (IsAbtractType) + if (IsAbstractType) return null; - if (!ConstructorInfo.HasValue || ConstructorInfo.Value.EmptyConstructor is null) + if (ConstructorInfo?.EmptyConstructor is null) return null; Expression newExp = Expression.New(ConstructorInfo.Value.EmptyConstructor); @@ -267,7 +267,7 @@ private TypeDeserializerFactory CreateDefaultFactory() } // is it abstract - if (IsAbtractType) + if (IsAbstractType) { RequiresTypeName = true; @@ -288,7 +288,7 @@ private TypeDeserializerFactory CreateDefaultFactory() if ((info = Children.FirstOrDefault(x => x.Value.EdgeDBTypeName == typeName).Value) is null) { throw new EdgeDBException( - $"Failed to deserialize the edgedb type '{typeName}'. Could not find relivant child of {_type.Name}"); + $"Failed to deserialize the EdgeDB type '{typeName}'. Could not find relevant child of {_type.Name}"); } // deserialize as child diff --git a/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs b/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs index a9591e8e..8437fb3a 100644 --- a/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs +++ b/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs @@ -287,7 +287,7 @@ internal static void ScanAssemblyForTypes(Assembly assembly) private static void ScanForAbstractTypes(Assembly assembly) { // look for any types that inherit already defined abstract types - foreach (var abstractType in TypeInfo.Where(x => x.Value.IsAbtractType)) + foreach (var abstractType in TypeInfo.Where(x => x.Value.IsAbstractType)) { var childTypes = assembly.DefinedTypes.Where(x => x.IsSubclassOf(abstractType.Key) || x.ImplementedInterfaces.Contains(abstractType.Key) || diff --git a/src/EdgeDB.Net.Driver/Binary/Codecs/ObjectCodec.cs b/src/EdgeDB.Net.Driver/Binary/Codecs/ObjectCodec.cs index f919e04d..80eda80e 100644 --- a/src/EdgeDB.Net.Driver/Binary/Codecs/ObjectCodec.cs +++ b/src/EdgeDB.Net.Driver/Binary/Codecs/ObjectCodec.cs @@ -41,7 +41,7 @@ public EdgeDBTypeDeserializeInfo Deserializer try { - return _deserializer.Factory(ref enumerator); + return _deserializer.Deserialize(ref enumerator); } catch (Exception x) { diff --git a/src/EdgeDB.Net.Driver/Binary/PacketReader.cs b/src/EdgeDB.Net.Driver/Binary/PacketReader.cs index ad8ec56d..2bea527a 100644 --- a/src/EdgeDB.Net.Driver/Binary/PacketReader.cs +++ b/src/EdgeDB.Net.Driver/Binary/PacketReader.cs @@ -49,6 +49,9 @@ public PacketReader(scoped in ReadOnlySpan bytes, int position = 0) _limit = Data.Length; } + public PacketReader CreateSubReader() + => new(Data, Position); + private void VerifyInLimits(int sz) { if (Position + sz > _limit) diff --git a/src/EdgeDB.Net.Driver/Clients/EdgeDBBinaryClient.cs b/src/EdgeDB.Net.Driver/Clients/EdgeDBBinaryClient.cs index 38f7656c..79d46e26 100644 --- a/src/EdgeDB.Net.Driver/Clients/EdgeDBBinaryClient.cs +++ b/src/EdgeDB.Net.Driver/Clients/EdgeDBBinaryClient.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using System.Collections.Immutable; +using System.Diagnostics; using System.Reflection; using ProtocolExecuteResult = EdgeDB.Binary.Protocol.ExecuteResult; @@ -92,19 +93,6 @@ internal ref Guid StateDescriptorId protected CancellationToken DisconnectCancelToken => Duplexer.DisconnectToken; - #region Events - - /// - /// Fired when the client disconnects. - /// - public event Func OnDisconnect - { - add => OnDisconnectInternal.Add(c => value()); - remove => OnDisconnectInternal.Remove(c => value()); - } - - #endregion - #region Client pool dispose /// diff --git a/src/EdgeDB.Net.Driver/Models/DataTypes/Json.cs b/src/EdgeDB.Net.Driver/Models/DataTypes/Json.cs index 2687e584..40b467da 100644 --- a/src/EdgeDB.Net.Driver/Models/DataTypes/Json.cs +++ b/src/EdgeDB.Net.Driver/Models/DataTypes/Json.cs @@ -42,6 +42,16 @@ public Json(string? value) ? serializer.Deserialize(new JsonTextReader(new StringReader(Value))) : EdgeDBConfig.JsonSerializer.DeserializeObject(Value); + /// + /// Serializes an to using the default + /// or if specified. + /// + /// The value to serialize. + /// The optional serializer to use when serializing. + /// The json representation of . + public static Json Serialize(object? value, JsonSerializer? serializer = null) + => (serializer ?? EdgeDBConfig.JsonSerializer).SerializeObject(value); + public static implicit operator string?(Json j) => j.Value; public static implicit operator Json(string? value) => new(value); } diff --git a/src/EdgeDB.Net.QueryBuilder/Extensions/TypeExtensions.cs b/src/EdgeDB.Net.QueryBuilder/Extensions/TypeExtensions.cs index f9e34da4..11b87312 100644 --- a/src/EdgeDB.Net.QueryBuilder/Extensions/TypeExtensions.cs +++ b/src/EdgeDB.Net.QueryBuilder/Extensions/TypeExtensions.cs @@ -10,13 +10,6 @@ namespace EdgeDB { internal static class TypeExtensions { - public static bool IsAnonymousType(this Type type) - { - return - type.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length > 0 && - type.FullName!.Contains("AnonymousType"); - } - public static IEnumerable GetEdgeDBTargetProperties(this Type type, bool excludeId = false) => type.GetProperties().Where(x => x.GetCustomAttribute() == null && !(excludeId && x.Name == "Id" && (x.PropertyType == typeof(Guid) || x.PropertyType == typeof(Guid?)))); @@ -30,7 +23,7 @@ public static string GetEdgeDBPropertyName(this MemberInfo info) { var att = info.GetCustomAttribute(); - return $"{((att?.IsLinkProperty ?? false) ? "@" : "")}{att?.Name ?? TypeBuilder.SchemaNamingStrategy.Convert(info)}"; + return $"{(att?.IsLinkProperty ?? false ? "@" : "")}{att?.Name ?? (info is PropertyInfo p ? TypeBuilder.SchemaNamingStrategy.Convert(p) : TypeBuilder.SchemaNamingStrategy.Convert(info.Name))}"; } public static Type GetMemberType(this MemberInfo info) diff --git a/src/EdgeDB.Net.QueryBuilder/QueryBuilder.cs b/src/EdgeDB.Net.QueryBuilder/QueryBuilder.cs index 78e70e1d..268aa874 100644 --- a/src/EdgeDB.Net.QueryBuilder/QueryBuilder.cs +++ b/src/EdgeDB.Net.QueryBuilder/QueryBuilder.cs @@ -87,14 +87,6 @@ private QueryNode? CurrentUserNode /// private readonly Dictionary _queryVariables; - /// - /// Initializes the . - /// - static QueryBuilder() - { - QueryObjectManager.Initialize(); - } - /// /// Constructs an empty query builder. /// diff --git a/src/EdgeDB.Net.QueryBuilder/QueryBuilder/QueryBuilder.With.cs b/src/EdgeDB.Net.QueryBuilder/QueryBuilder/QueryBuilder.With.cs index 5d7dec90..29c4f38e 100644 --- a/src/EdgeDB.Net.QueryBuilder/QueryBuilder/QueryBuilder.With.cs +++ b/src/EdgeDB.Net.QueryBuilder/QueryBuilder/QueryBuilder.With.cs @@ -76,13 +76,14 @@ public QueryBuilder> With(TVa // add it as a sub-query _queryGlobals.Add(new QueryGlobal(property.Name, value)); } - else if ( - EdgeDBTypeUtils.IsLink(property.PropertyType, out var isMultiLink, out var innerType) - && !isMultiLink - && QueryObjectManager.TryGetObjectId(value, out var id)) - { - _queryGlobals.Add(new QueryGlobal(property.Name, new SubQuery($"(select {property.PropertyType.GetEdgeDBTypeName()} filter .id = '{id}')"))); - } + // TODO: revisit references + //else if ( + // EdgeDBTypeUtils.IsLink(property.PropertyType, out var isMultiLink, out var innerType) + // && !isMultiLink + // && QueryObjectManager.TryGetObjectId(value, out var id)) + //{ + // _queryGlobals.Add(new QueryGlobal(property.Name, new SubQuery($"(select {property.PropertyType.GetEdgeDBTypeName()} filter .id = '{id}')"))); + //} else if (ReflectionUtils.IsSubclassOfRawGeneric(typeof(JsonReferenceVariable<>), property.PropertyType)) { // serialize and add as global and variable diff --git a/src/EdgeDB.Net.QueryBuilder/QueryNodes/InsertNode.cs b/src/EdgeDB.Net.QueryBuilder/QueryNodes/InsertNode.cs index 98f60d71..4697c575 100644 --- a/src/EdgeDB.Net.QueryBuilder/QueryNodes/InsertNode.cs +++ b/src/EdgeDB.Net.QueryBuilder/QueryNodes/InsertNode.cs @@ -100,7 +100,7 @@ private readonly struct ShapeDefinition /// Whether or not the setter requires introspection. /// public readonly bool RequiresIntrospection; - + /// /// The raw string form shape definition, if any. /// @@ -183,13 +183,13 @@ public string Build(SchemaInfo info) private readonly StringBuilder _elseStatement; /// - /// The list of currently inserted types used to determine if + /// The list of currently inserted types used to determine if /// a nested query can be preformed. /// private readonly List _subQueryMap = new(); /// - public InsertNode(NodeBuilder builder) : base(builder) + public InsertNode(NodeBuilder builder) : base(builder) { _elseStatement = new(); } @@ -201,8 +201,8 @@ public override void Visit() _subQueryMap.Add(OperatingType); // build the insert shape - _shape = Context.IsJsonVariable - ? BuildJsonShape() + _shape = Context.IsJsonVariable + ? BuildJsonShape() : BuildInsertShape(); RequiresIntrospection = _shape.RequiresIntrospection; @@ -212,8 +212,8 @@ public override void Visit() public override void FinalizeQuery() { // build the shape with introspection - var shape = SchemaInfo is not null - ? _shape.Build(SchemaInfo) + var shape = SchemaInfo is not null + ? _shape.Build(SchemaInfo) : _shape.Build(); // prepend it to our query string @@ -230,7 +230,7 @@ public override void FinalizeQuery() Query.Append($" {ConflictUtils.GenerateExclusiveConflictStatement(typeInfo, _elseStatement.Length != 0)}"); } - + Query.Append(_elseStatement); // if the query builder wants this node as a global @@ -282,7 +282,7 @@ private ShapeDefinition BuildJsonShape() var edgedbName = x.GetEdgeDBPropertyName(); var isScalar = EdgeDBTypeUtils.TryGetScalarType(x.PropertyType, out var edgeqlType); - // we need to add a callback for value types that are default to determine if we need to + // we need to add a callback for value types that are default to determine if we need to // add the setter if (isScalar && x.PropertyType.IsValueType && !x.PropertyType.IsEnum) { @@ -305,7 +305,7 @@ private ShapeDefinition BuildJsonShape() if (EdgeDBTypeUtils.IsLink(x.PropertyType, out var isArray, out _)) { // if we're in the last iteration of the depth map, we know for certian there - // are no sub types within the current context, we can safely set the link to + // are no sub types within the current context, we can safely set the link to // an empty set if (isLast) return $"{edgedbName} := {{}}"; @@ -357,7 +357,7 @@ private ShapeDefinition BuildJsonShape() var edgedbName = x.GetEdgeDBPropertyName(); var isScalar = EdgeDBTypeUtils.TryGetScalarType(x.PropertyType, out var edgeqlType); - // we need to add a callback for value types that are default to determine if we need to + // we need to add a callback for value types that are default to determine if we need to // add the setter if (isScalar && x.PropertyType.IsValueType && !x.PropertyType.IsEnum) { @@ -431,7 +431,7 @@ private ShapeDefinition BuildInsertShape(Type? shapeType = null, object? shapeVa // define the type and whether or not it's a link var propValue = property.PropertyInfo.GetValue(value); var isScalar = EdgeDBTypeUtils.TryGetScalarType(property.Type, out var edgeqlType); - + if(property.CustomConverter is not null) { // convert it and parameterize it @@ -443,12 +443,12 @@ private ShapeDefinition BuildInsertShape(Type? shapeType = null, object? shapeVa setters.Add($"{property.EdgeDBName} := <{scalar}>${varName}"); continue; } - + // if its a default value of a struct, ignore it. if (isScalar && property.Type.IsValueType && !property.Type.IsEnum && - (propValue?.Equals(ReflectionUtils.GetValueTypeDefault(property.Type)) ?? false)) + (propValue?.Equals(ReflectionUtils.GetDefault(property.Type)) ?? false)) { setters.Add(new(s => { @@ -532,34 +532,33 @@ private string BuildLinkResolver(Type type, object? value) if (value is null) return "{}"; - // is it a value thats been returned from a previous query? - if (QueryObjectManager.TryGetObjectId(value, out var id)) - { - // add a sub select statement - return InlineOrGlobal( - type, - new SubQuery($"(select {type.GetEdgeDBTypeName()} filter .id = \"{id}\")"), - value); - } - else - { - RequiresIntrospection = true; + // TODO: revisit references. + //// is it a value that's been returned from a previous query? + //if (QueryObjectManager.TryGetObjectId(value, out var id)) + //{ + // // add a sub select statement + // return InlineOrGlobal( + // type, + // new SubQuery($"(select {type.GetEdgeDBTypeName()} filter .id = \"{id}\")"), + // value); + //} - // add a insert select statement - return InlineOrGlobal(type, new SubQuery((info) => - { - var name = type.GetEdgeDBTypeName(); - var exclusiveProps = QueryGenerationUtils.GetProperties(info, type, true); - var exclusiveCondition = exclusiveProps.Any() ? - $" unless conflict on {(exclusiveProps.Count() > 1 ? $"({string.Join(", ", exclusiveProps.Select(x => $".{x.GetEdgeDBPropertyName()}"))})" : $".{exclusiveProps.First().GetEdgeDBPropertyName()}")} else (select {name})" - : string.Empty; - return $"(insert {name} {BuildInsertShape(type, value).Build(info)}{exclusiveCondition})"; - }), value); - } + RequiresIntrospection = true; + + // add a insert select statement + return InlineOrGlobal(type, new SubQuery((info) => + { + var name = type.GetEdgeDBTypeName(); + var exclusiveProps = QueryGenerationUtils.GetProperties(info, type, true); + var exclusiveCondition = exclusiveProps.Any() ? + $" unless conflict on {(exclusiveProps.Count() > 1 ? $"({string.Join(", ", exclusiveProps.Select(x => $".{x.GetEdgeDBPropertyName()}"))})" : $".{exclusiveProps.First().GetEdgeDBPropertyName()}")} else (select {name})" + : string.Empty; + return $"(insert {name} {BuildInsertShape(type, value).Build(info)}{exclusiveCondition})"; + }), value); } /// - /// Adds a sub query as an inline query or as a global depending on if the current + /// Adds a sub query as an inline query or as a global depending on if the current /// query contains any statements for the provided type. /// /// The returning type of the sub query. diff --git a/src/EdgeDB.Net.QueryBuilder/QueryObjectManager.cs b/src/EdgeDB.Net.QueryBuilder/QueryObjectManager.cs deleted file mode 100644 index 31d5192f..00000000 --- a/src/EdgeDB.Net.QueryBuilder/QueryObjectManager.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EdgeDB -{ - /// - /// Represents a class that contains safe references to objects returned in queries. - /// - internal class QueryObjectManager - { - /// - /// A containing the s. - /// - private static readonly HashSet _references = new(); - - /// - /// Initializes the object manager, creating a hook to the - /// to get any objects returned from queries. - /// - public static void Initialize() - { - TypeBuilder.OnObjectCreated += OnObjectCreated; - } - - /// - /// Attempts to get the EdgeDB object id for the given instance. - /// - /// The object instance to get the id from. - /// The out parameter containing the id of the provided object. - /// - /// if the object instance matched one that was - /// returned from a previous query, otherwise . - /// - public static bool TryGetObjectId(object? obj, out Guid id) - { - id = default; - if (obj == null) - return false; - - var reference = _references.FirstOrDefault(x => x.Reference.IsAlive && x.Reference.Target == obj); - id = reference?.ObjectId ?? default; - return reference != null; - } - - /// - /// The callback to add new references to . - /// - /// The object returned from the query. - /// The id of the object. - private static void OnObjectCreated(object obj, Guid id) - { - var reference = new QueryObjectReference(id, new WeakReference(obj)); - _references.Add(reference); - } - - /// - /// Represents a wrapped containing the reference and the object id. - /// - private class QueryObjectReference - { - /// - /// The id of the object within the . - /// - public readonly Guid ObjectId; - - /// - /// The weak reference to a returned query object. - /// - public readonly WeakReference Reference; - - /// - /// Constructs a new . - /// - /// The object id of the reference. - /// The weak reference pointing to a returned query object. - public QueryObjectReference(Guid objectId, WeakReference reference) - { - ObjectId = objectId; - Reference = reference; - } - } - } -} diff --git a/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/InitializationTranslator.cs b/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/InitializationTranslator.cs index 7cf622db..2f9248aa 100644 --- a/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/InitializationTranslator.cs +++ b/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/InitializationTranslator.cs @@ -131,13 +131,14 @@ public static Dictionary PullInitializationExpression(Ex break; } + // TODO: revisit references // check if its a value returned in a previous query - if (QueryObjectManager.TryGetObjectId(memberValue, out var id)) - { - var globalName = context.GetOrAddGlobal(id, id.SelectSubQuery(property.Type)); - initializations.Add($"{property.EdgeDBName} := {globalName}"); - break; - } + //if (QueryObjectManager.TryGetObjectId(memberValue, out var id)) + //{ + // var globalName = context.GetOrAddGlobal(id, id.SelectSubQuery(property.Type)); + // initializations.Add($"{property.EdgeDBName} := {globalName}"); + // break; + //} // generate an insert or select based on its unique constraints. var name = QueryUtils.GenerateRandomVariableName(); diff --git a/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/UnaryExpressionTranslator.cs b/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/UnaryExpressionTranslator.cs index b36467ff..65986a99 100644 --- a/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/UnaryExpressionTranslator.cs +++ b/src/EdgeDB.Net.QueryBuilder/Translators/Expressions/UnaryExpressionTranslator.cs @@ -26,7 +26,7 @@ internal class UnaryExpressionTranslator : ExpressionTranslator case ExpressionType.Convert: { var value = TranslateExpression(expression.Operand, context); - + if (value is null) return null; // nullable converters for include, ex Guid? -> Guid @@ -36,17 +36,17 @@ internal class UnaryExpressionTranslator : ExpressionTranslator return value; // dotnet nullable check - if (ReflectionUtils.IsSubclassOfRawGeneric(typeof(Nullable<>), expression.Type) && + if (ReflectionUtils.IsSubclassOfRawGeneric(typeof(Nullable<>), expression.Type) && expression.Type.GenericTypeArguments[0] == expression.Operand.Type) { - // no need to cast in edgedb, return the value + // no need to cast in edgedb, return the value return value; } - var type = EdgeDBTypeUtils.TryGetScalarType(expression.Type, out var edgedbType) + var type = EdgeDBTypeUtils.TryGetScalarType(expression.Type, out var edgedbType) ? edgedbType.ToString() : expression.Type.GetEdgeDBTypeName(); - + return $"<{type}>{value}"; } case ExpressionType.ArrayLength: @@ -60,7 +60,7 @@ internal class UnaryExpressionTranslator : ExpressionTranslator return op.Build(TranslateExpression(expression.Operand, context)); } - throw new NotSupportedException($"Failed to find converter for {expression.NodeType}!"); + //throw new NotSupportedException($"Failed to find converter for {expression.NodeType}!"); } } } diff --git a/src/EdgeDB.Net.QueryBuilder/Utils/QueryGenerationUtils.cs b/src/EdgeDB.Net.QueryBuilder/Utils/QueryGenerationUtils.cs index 93d1101f..2f5c7886 100644 --- a/src/EdgeDB.Net.QueryBuilder/Utils/QueryGenerationUtils.cs +++ b/src/EdgeDB.Net.QueryBuilder/Utils/QueryGenerationUtils.cs @@ -139,9 +139,10 @@ public static async ValueTask>> GenerateUpdateFact /// public static async ValueTask, bool>>> GenerateUpdateFilterAsync(IEdgeDBQueryable edgedb, TType value, CancellationToken token = default) { + // TODO: revisit references // try and get object id - if (QueryObjectManager.TryGetObjectId(value, out var id)) - return (_, ctx) => ctx.UnsafeLocal("id") == id; + //if (QueryObjectManager.TryGetObjectId(value, out var id)) + // return (_, ctx) => ctx.UnsafeLocal("id") == id; // get exclusive properties. var exclusiveProperties = await GetPropertiesAsync(edgedb, exclusive: true, token: token).ConfigureAwait(false); diff --git a/src/EdgeDB.Net.Queryable/EdgeDBQueryProvider.cs b/src/EdgeDB.Net.Queryable/EdgeDBQueryProvider.cs index f1d733fd..e326393e 100644 --- a/src/EdgeDB.Net.Queryable/EdgeDBQueryProvider.cs +++ b/src/EdgeDB.Net.Queryable/EdgeDBQueryProvider.cs @@ -13,6 +13,7 @@ internal class EdgeDBQueryProvider : IQueryProvider public IShapeBuilder? Shape { get; set; } private readonly List _parts; + public EdgeDBQueryProvider() { _parts = new List(); diff --git a/src/EdgeDB.Net.Queryable/GenericlessQueryBuilder.cs b/src/EdgeDB.Net.Queryable/GenericlessQueryBuilder.cs index 0a840f25..b8bceca1 100644 --- a/src/EdgeDB.Net.Queryable/GenericlessQueryBuilder.cs +++ b/src/EdgeDB.Net.Queryable/GenericlessQueryBuilder.cs @@ -117,13 +117,14 @@ public GenericlessQueryBuilder With(object variables) // add it as a sub-query _queryGlobals.Add(new QueryGlobal(property.Name, value)); } - else if ( - EdgeDBTypeUtils.IsLink(property.PropertyType, out var isMultiLink, out var innerType) - && !isMultiLink - && QueryObjectManager.TryGetObjectId(value, out var id)) - { - _queryGlobals.Add(new QueryGlobal(property.Name, new SubQuery($"(select {property.PropertyType.GetEdgeDBTypeName()} filter .id = '{id}')"))); - } + // TODO: revisit references + //else if ( + // EdgeDBTypeUtils.IsLink(property.PropertyType, out var isMultiLink, out var innerType) + // && !isMultiLink + // && QueryObjectManager.TryGetObjectId(value, out var id)) + //{ + // _queryGlobals.Add(new QueryGlobal(property.Name, new SubQuery($"(select {property.PropertyType.GetEdgeDBTypeName()} filter .id = '{id}')"))); + //} else if (ReflectionUtils.IsSubclassOfRawGeneric(typeof(JsonReferenceVariable<>), property.PropertyType)) { // Serialize and add as global and variable diff --git a/tools/EdgeDB.QueryBuilder.StandardLibGenerator/OperatorGenerator.cs b/tools/EdgeDB.QueryBuilder.StandardLibGenerator/OperatorGenerator.cs index c6da7edb..1712bea9 100644 --- a/tools/EdgeDB.QueryBuilder.StandardLibGenerator/OperatorGenerator.cs +++ b/tools/EdgeDB.QueryBuilder.StandardLibGenerator/OperatorGenerator.cs @@ -164,7 +164,7 @@ private static string BuildExpression(Operator op) case OperatorKind.Infix: { if (op.Parameters!.Length != 2) - throw new ArgumentException("Expected 2 paramets for Infix"); + throw new ArgumentException("Expected 2 parameters for Infix"); return op.Name switch { @@ -175,21 +175,21 @@ private static string BuildExpression(Operator op) case OperatorKind.Postfix: { if (op.Parameters!.Length != 1) - throw new ArgumentException("Expected 1 paramets for Postfix"); + throw new ArgumentException("Expected 1 parameter for Postfix"); return $"{{{op.Parameters[0].Name + "Param"}}} {operation}"; } case OperatorKind.Prefix: { if (op.Parameters!.Length != 1) - throw new ArgumentException("Expected 1 paramets for Prefix"); + throw new ArgumentException("Expected 1 parameter for Prefix"); return $"{operation} {{{op.Parameters[0].Name + "Param"}}}"; } case OperatorKind.Ternary: { if (op.Parameters!.Length != 3) - throw new ArgumentException("Expected 3 paramets for Ternary"); + throw new ArgumentException("Expected 3 parameters for Ternary"); return $"{{{op.Parameters[0].Name + "Param"}}} IF {{{op.Parameters[1].Name + "Param"}}} ELSE {{{op.Parameters[2].Name + "Param"}}}"; }