From 0ff61428abbcd7e1ff4bf8d4c77ebb5cfa544c5f Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Fri, 27 Oct 2023 21:22:11 +0200 Subject: [PATCH] Rename Postgres*Expression to Pg*Expression --- ...TopologySuiteMethodCallTranslatorPlugin.cs | 2 +- ...pgsqlNodaTimeMethodCallTranslatorPlugin.cs | 18 +- .../NpgsqlByteArrayMethodTranslator.cs | 2 +- .../NpgsqlDateTimeMethodTranslator.cs | 4 +- .../NpgsqlFullTextSearchMethodTranslator.cs | 6 +- .../NpgsqlJsonDbFunctionsTranslator.cs | 16 +- .../Internal/NpgsqlJsonDomTranslator.cs | 6 +- .../Internal/NpgsqlJsonPocoTranslator.cs | 8 +- .../Internal/NpgsqlLTreeTranslator.cs | 16 +- .../NpgsqlMiscAggregateMethodTranslator.cs | 2 +- .../Internal/NpgsqlNetworkTranslator.cs | 6 +- .../Internal/NpgsqlRangeTranslator.cs | 16 +- .../Internal/NpgsqlRowValueTranslator.cs | 6 +- ...gsqlStatisticsAggregateMethodTranslator.cs | 2 +- .../Internal/NpgsqlStringMethodTranslator.cs | 2 +- .../NpgsqlTrigramsMethodTranslator.cs | 4 +- ...resAllExpression.cs => PgAllExpression.cs} | 26 +- ...resAnyExpression.cs => PgAnyExpression.cs} | 30 +- ...xpression.cs => PgArrayIndexExpression.cs} | 14 +- ...xpression.cs => PgArraySliceExpression.cs} | 14 +- ...aryExpression.cs => PgBinaryExpression.cs} | 86 +++--- ...eteExpression.cs => PgDeleteExpression.cs} | 14 +- ...nExpression.cs => PgFunctionExpression.cs} | 32 +- ...LikeExpression.cs => PgILikeExpression.cs} | 14 +- ...ession.cs => PgJsonTraversalExpression.cs} | 20 +- ...yExpression.cs => PgNewArrayExpression.cs} | 24 +- ...xpression.cs => PgRegexMatchExpression.cs} | 14 +- ...eExpression.cs => PgRowValueExpression.cs} | 14 +- ...ession.cs => PgUnknownBinaryExpression.cs} | 14 +- ...estExpression.cs => PgUnnestExpression.cs} | 12 +- ...sExpressionType.cs => PgExpressionType.cs} | 28 +- ...NpgsqlDeleteConvertingExpressionVisitor.cs | 4 +- .../Query/Internal/NpgsqlQuerySqlGenerator.cs | 160 +++++----- ...yableMethodTranslatingExpressionVisitor.cs | 134 ++++---- .../Internal/NpgsqlSqlNullabilityProcessor.cs | 76 ++--- .../NpgsqlSqlTranslatingExpressionVisitor.cs | 4 +- .../Internal/NpgsqlUnnestPostprocessor.cs | 8 +- .../Query/NpgsqlSqlExpressionFactory.cs | 292 +++++++++--------- 38 files changed, 575 insertions(+), 575 deletions(-) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresAllExpression.cs => PgAllExpression.cs} (80%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresAnyExpression.cs => PgAnyExpression.cs} (80%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresArrayIndexExpression.cs => PgArrayIndexExpression.cs} (86%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresArraySliceExpression.cs => PgArraySliceExpression.cs} (85%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresBinaryExpression.cs => PgBinaryExpression.cs} (63%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresDeleteExpression.cs => PgDeleteExpression.cs} (86%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresFunctionExpression.cs => PgFunctionExpression.cs} (91%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresILikeExpression.cs => PgILikeExpression.cs} (85%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresJsonTraversalExpression.cs => PgJsonTraversalExpression.cs} (78%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresNewArrayExpression.cs => PgNewArrayExpression.cs} (80%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresRegexMatchExpression.cs => PgRegexMatchExpression.cs} (82%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresRowValueExpression.cs => PgRowValueExpression.cs} (84%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresUnknownBinaryExpression.cs => PgUnknownBinaryExpression.cs} (83%) rename src/EFCore.PG/Query/Expressions/Internal/{PostgresUnnestExpression.cs => PgUnnestExpression.cs} (92%) rename src/EFCore.PG/Query/Expressions/{PostgresExpressionType.cs => PgExpressionType.cs} (98%) diff --git a/src/EFCore.PG.NTS/Query/ExpressionTranslators/Internal/NpgsqlNetTopologySuiteMethodCallTranslatorPlugin.cs b/src/EFCore.PG.NTS/Query/ExpressionTranslators/Internal/NpgsqlNetTopologySuiteMethodCallTranslatorPlugin.cs index b96d9899f..577c23c0b 100644 --- a/src/EFCore.PG.NTS/Query/ExpressionTranslators/Internal/NpgsqlNetTopologySuiteMethodCallTranslatorPlugin.cs +++ b/src/EFCore.PG.NTS/Query/ExpressionTranslators/Internal/NpgsqlNetTopologySuiteMethodCallTranslatorPlugin.cs @@ -109,7 +109,7 @@ public NpgsqlGeometryMethodTranslator( arguments[1].TypeMapping), nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.DistanceKnn) => _sqlExpressionFactory.MakePostgresBinary( - PostgresExpressionType.Distance, + PgExpressionType.Distance, arguments[1], arguments[2]), diff --git a/src/EFCore.PG.NodaTime/Query/Internal/NpgsqlNodaTimeMethodCallTranslatorPlugin.cs b/src/EFCore.PG.NodaTime/Query/Internal/NpgsqlNodaTimeMethodCallTranslatorPlugin.cs index c918467e3..52db1133f 100644 --- a/src/EFCore.PG.NodaTime/Query/Internal/NpgsqlNodaTimeMethodCallTranslatorPlugin.cs +++ b/src/EFCore.PG.NodaTime/Query/Internal/NpgsqlNodaTimeMethodCallTranslatorPlugin.cs @@ -203,7 +203,7 @@ public NpgsqlNodaTimeMethodCallTranslator( if (method == Instant_Distance) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]); } return null; @@ -232,7 +232,7 @@ public NpgsqlNodaTimeMethodCallTranslator( if (method == ZonedDateTime_Distance) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]); } return null; @@ -250,7 +250,7 @@ public NpgsqlNodaTimeMethodCallTranslator( if (method == LocalDateTime_Distance) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]); } return null; @@ -263,7 +263,7 @@ public NpgsqlNodaTimeMethodCallTranslator( { if (method == LocalDate_Distance) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]); } return null; @@ -318,8 +318,8 @@ public NpgsqlNodaTimeMethodCallTranslator( return null; - static PostgresFunctionExpression IntervalPart(string datePart, SqlExpression parameter) - => PostgresFunctionExpression.CreateWithNamedArguments( + static PgFunctionExpression IntervalPart(string datePart, SqlExpression parameter) + => PgFunctionExpression.CreateWithNamedArguments( "make_interval", new[] { parameter }, new[] { datePart }, @@ -329,7 +329,7 @@ static PostgresFunctionExpression IntervalPart(string datePart, SqlExpression pa typeof(Period), typeMapping: null); - PostgresFunctionExpression IntervalPartOverBigInt(string datePart, SqlExpression parameter) + PgFunctionExpression IntervalPartOverBigInt(string datePart, SqlExpression parameter) { parameter = _sqlExpressionFactory.ApplyDefaultTypeMapping(parameter); @@ -376,12 +376,12 @@ PostgresFunctionExpression IntervalPartOverBigInt(string datePart, SqlExpression if (method == DateInterval_Intersection) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIntersect, instance!, arguments[0]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIntersect, instance!, arguments[0]); } if (method == DateInterval_Union) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeUnion, instance!, arguments[0]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeUnion, instance!, arguments[0]); } return null; diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlByteArrayMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlByteArrayMethodTranslator.cs index ea3ae50c9..a775876bd 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlByteArrayMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlByteArrayMethodTranslator.cs @@ -66,7 +66,7 @@ public NpgsqlByteArrayMethodTranslator(ISqlExpressionFactory sqlExpressionFactor typeMapping); return _sqlExpressionFactory.GreaterThan( - PostgresFunctionExpression.CreateWithArgumentSeparators( + PgFunctionExpression.CreateWithArgumentSeparators( "position", new[] { value, source }, new[] { "IN" }, // POSITION(x IN y) diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs index 09245cee3..99ad4cd32 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs @@ -204,7 +204,7 @@ public NpgsqlDateTimeMethodTranslator( if (method == DateTime_Distance) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]); } } else @@ -249,7 +249,7 @@ public NpgsqlDateTimeMethodTranslator( if (method == DateOnly_Distance) { - return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]); + return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]); } } else diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlFullTextSearchMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlFullTextSearchMethodTranslator.cs index eec423f94..3d26addd3 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlFullTextSearchMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlFullTextSearchMethodTranslator.cs @@ -144,9 +144,9 @@ public NpgsqlFullTextSearchMethodTranslator( // Operators nameof(NpgsqlFullTextSearchLinqExtensions.And) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.TextSearchAnd, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.TextSearchAnd, arguments[0], arguments[1]), nameof(NpgsqlFullTextSearchLinqExtensions.Or) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.TextSearchOr, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.TextSearchOr, arguments[0], arguments[1]), nameof(NpgsqlFullTextSearchLinqExtensions.ToNegative) => new SqlUnaryExpression(ExpressionType.Not, arguments[0], arguments[0].Type, @@ -162,7 +162,7 @@ public NpgsqlFullTextSearchMethodTranslator( nameof(NpgsqlFullTextSearchLinqExtensions.Matches) => _sqlExpressionFactory.MakePostgresBinary( - PostgresExpressionType.TextSearchMatch, + PgExpressionType.TextSearchMatch, arguments[0], arguments[1].Type == typeof(string) ? _sqlExpressionFactory.Function( diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs index 01211b992..0cf35c2a4 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs @@ -60,10 +60,10 @@ public NpgsqlJsonDbFunctionsTranslator( // If a function is invoked over a JSON traversal expression, that expression may come with // returnText: true (i.e. operator ->> and not ->). Since the functions below require a json object and // not text, we transform it. - .Select(a => a is PostgresJsonTraversalExpression traversal ? WithReturnsText(traversal, false) : a) + .Select(a => a is PgJsonTraversalExpression traversal ? WithReturnsText(traversal, false) : a) .ToArray(); - if (!args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping || a is PostgresJsonTraversalExpression)) + if (!args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping || a is PgJsonTraversalExpression)) { throw new InvalidOperationException("The EF JSON methods require a JSON parameter and none was found."); } @@ -91,11 +91,11 @@ public NpgsqlJsonDbFunctionsTranslator( nameof(NpgsqlJsonDbFunctionsExtensions.JsonContained) => _sqlExpressionFactory.ContainedBy(Jsonb(args[0]), Jsonb(args[1])), nameof(NpgsqlJsonDbFunctionsExtensions.JsonExists) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.JsonExists, Jsonb(args[0]), args[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.JsonExists, Jsonb(args[0]), args[1]), nameof(NpgsqlJsonDbFunctionsExtensions.JsonExistAny) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.JsonExistsAny, Jsonb(args[0]), args[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.JsonExistsAny, Jsonb(args[0]), args[1]), nameof(NpgsqlJsonDbFunctionsExtensions.JsonExistAll) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.JsonExistsAll, Jsonb(args[0]), args[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.JsonExistsAll, Jsonb(args[0]), args[1]), _ => null }; @@ -117,11 +117,11 @@ static SqlExpression RemoveConvert(SqlExpression e) return e; } - PostgresJsonTraversalExpression WithReturnsText(PostgresJsonTraversalExpression traversal, bool returnsText) + PgJsonTraversalExpression WithReturnsText(PgJsonTraversalExpression traversal, bool returnsText) => traversal.ReturnsText == returnsText ? traversal : returnsText - ? new PostgresJsonTraversalExpression(traversal.Expression, traversal.Path, true, typeof(string), _stringTypeMapping) - : new PostgresJsonTraversalExpression(traversal.Expression, traversal.Path, false, traversal.Type, traversal.Expression.TypeMapping); + ? new PgJsonTraversalExpression(traversal.Expression, traversal.Path, true, typeof(string), _stringTypeMapping) + : new PgJsonTraversalExpression(traversal.Expression, traversal.Path, false, traversal.Type, traversal.Expression.TypeMapping); } } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs index d1f6e07a7..8747c7652 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs @@ -113,16 +113,16 @@ public NpgsqlJsonDomTranslator( if (method == GetProperty || method == ArrayIndexer) { - return instance is PostgresJsonTraversalExpression prevPathTraversal + return instance is PgJsonTraversalExpression prevPathTraversal ? prevPathTraversal.Append(_sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0])) : null; } if (GetMethods.Contains(method.Name) && arguments.Count == 0 && - instance is PostgresJsonTraversalExpression traversal) + instance is PgJsonTraversalExpression traversal) { - var traversalToText = new PostgresJsonTraversalExpression( + var traversalToText = new PgJsonTraversalExpression( traversal.Expression, traversal.Path, returnsText: true, diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonPocoTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonPocoTranslator.cs index 3600f9f4d..0b4fe3015 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonPocoTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonPocoTranslator.cs @@ -73,7 +73,7 @@ public NpgsqlJsonPocoTranslator( Type returnType, IDiagnosticsLogger logger) { - if (instance?.TypeMapping is not NpgsqlJsonTypeMapping && instance is not PostgresJsonTraversalExpression) + if (instance?.TypeMapping is not NpgsqlJsonTypeMapping && instance is not PgJsonTraversalExpression) { return null; } @@ -111,7 +111,7 @@ public NpgsqlJsonPocoTranslator( _stringTypeMapping), returnType), - PostgresJsonTraversalExpression prevPathTraversal + PgJsonTraversalExpression prevPathTraversal => ConvertFromText( prevPathTraversal.Append(_sqlExpressionFactory.ApplyDefaultTypeMapping(member)), returnType), @@ -137,11 +137,11 @@ PostgresJsonTraversalExpression prevPathTraversal argumentsPropagateNullability: TrueArrays[2], typeof(int)); - case PostgresJsonTraversalExpression traversal: + case PgJsonTraversalExpression traversal: // The traversal expression has ReturnsText=true (e.g. ->> not ->), so we recreate it to return // the JSON object instead. var lastPathComponent = traversal.Path.Last(); - var newTraversal = new PostgresJsonTraversalExpression( + var newTraversal = new PgJsonTraversalExpression( traversal.Expression, traversal.Path, returnsText: false, lastPathComponent.Type, diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLTreeTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLTreeTranslator.cs index 2866a6625..e699d2fab 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLTreeTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLTreeTranslator.cs @@ -67,32 +67,32 @@ public NpgsqlLTreeTranslator( return method.Name switch { nameof(LTree.IsAncestorOf) - => new PostgresBinaryExpression( - PostgresExpressionType.Contains, + => new PgBinaryExpression( + PgExpressionType.Contains, ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping), ApplyTypeMappingOrConvert(arguments[0], _ltreeTypeMapping), typeof(bool), _boolTypeMapping), nameof(LTree.IsDescendantOf) - => new PostgresBinaryExpression( - PostgresExpressionType.ContainedBy, + => new PgBinaryExpression( + PgExpressionType.ContainedBy, ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping), ApplyTypeMappingOrConvert(arguments[0], _ltreeTypeMapping), typeof(bool), _boolTypeMapping), nameof(LTree.MatchesLQuery) - => new PostgresBinaryExpression( - PostgresExpressionType.LTreeMatches, + => new PgBinaryExpression( + PgExpressionType.LTreeMatches, ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping), ApplyTypeMappingOrConvert(arguments[0], _lqueryTypeMapping), typeof(bool), _boolTypeMapping), nameof(LTree.MatchesLTxtQuery) - => new PostgresBinaryExpression( - PostgresExpressionType.LTreeMatches, + => new PgBinaryExpression( + PgExpressionType.LTreeMatches, ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping), ApplyTypeMappingOrConvert(arguments[0], _ltxtqueryTypeMapping), typeof(bool), diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMiscAggregateMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMiscAggregateMethodTranslator.cs index f56f6f2fc..27eafcf8a 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMiscAggregateMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMiscAggregateMethodTranslator.cs @@ -148,7 +148,7 @@ public NpgsqlMiscAggregateMethodTranslator( // These methods accept two enumerable (column) arguments; this is represented in LINQ as a projection from the grouping // to a tuple of the two columns. Since we generally translate tuples to PostgresRowValueExpression, we take it apart // here. - if (source.Selector is not PostgresRowValueExpression rowValueExpression) + if (source.Selector is not PgRowValueExpression rowValueExpression) { return null; } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs index 3f209035c..aa9135555 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs @@ -125,14 +125,14 @@ public NpgsqlNetworkTranslator( => _sqlExpressionFactory.ContainedBy(arguments[1], arguments[2]), nameof(NpgsqlNetworkDbFunctionsExtensions.ContainedByOrEqual) => _sqlExpressionFactory.MakePostgresBinary( - PostgresExpressionType.NetworkContainedByOrEqual, arguments[1], arguments[2]), + PgExpressionType.NetworkContainedByOrEqual, arguments[1], arguments[2]), nameof(NpgsqlNetworkDbFunctionsExtensions.Contains) => _sqlExpressionFactory.Contains(arguments[1], arguments[2]), nameof(NpgsqlNetworkDbFunctionsExtensions.ContainsOrEqual) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.NetworkContainsOrEqual, arguments[1], arguments[2]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.NetworkContainsOrEqual, arguments[1], arguments[2]), nameof(NpgsqlNetworkDbFunctionsExtensions.ContainsOrContainedBy) => _sqlExpressionFactory.MakePostgresBinary( - PostgresExpressionType.NetworkContainsOrContainedBy, arguments[1], arguments[2]), + PgExpressionType.NetworkContainsOrContainedBy, arguments[1], arguments[2]), nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseNot) => new SqlUnaryExpression( diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs index f5af48d1e..40e43bc2c 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs @@ -111,21 +111,21 @@ public NpgsqlRangeTranslator( nameof(NpgsqlRangeDbFunctionsExtensions.Overlaps) => _sqlExpressionFactory.Overlaps(arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.IsStrictlyLeftOf) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIsStrictlyLeftOf, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIsStrictlyLeftOf, arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.IsStrictlyRightOf) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIsStrictlyRightOf, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIsStrictlyRightOf, arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.DoesNotExtendRightOf) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeDoesNotExtendRightOf, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeDoesNotExtendRightOf, arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.DoesNotExtendLeftOf) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeDoesNotExtendLeftOf, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeDoesNotExtendLeftOf, arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.IsAdjacentTo) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIsAdjacentTo, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIsAdjacentTo, arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.Union) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeUnion, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeUnion, arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.Intersect) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIntersect, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIntersect, arguments[0], arguments[1]), nameof(NpgsqlRangeDbFunctionsExtensions.Except) - => _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeExcept, arguments[0], arguments[1]), + => _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeExcept, arguments[0], arguments[1]), _ => null }; diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs index b8116cb60..eb43c3271 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs @@ -60,7 +60,7 @@ public NpgsqlRowValueTranslator(NpgsqlSqlExpressionFactory sqlExpressionFactory) // Translate ValueTuple.Create if (method.DeclaringType == typeof(ValueTuple) && method is { IsStatic: true, Name: nameof(ValueTuple.Create) }) { - return new PostgresRowValueExpression(arguments, method.ReturnType); + return new PgRowValueExpression(arguments, method.ReturnType); } // Translate EF.Functions.GreaterThan and other comparisons @@ -69,13 +69,13 @@ public NpgsqlRowValueTranslator(NpgsqlSqlExpressionFactory sqlExpressionFactory) return null; } - var leftCount = arguments[1] is PostgresRowValueExpression leftRowValue + var leftCount = arguments[1] is PgRowValueExpression leftRowValue ? leftRowValue.Values.Count : arguments[1] is SqlConstantExpression { Value : ITuple leftTuple } ? (int?)leftTuple.Length : null; - var rightCount = arguments[2] is PostgresRowValueExpression rightRowValue + var rightCount = arguments[2] is PgRowValueExpression rightRowValue ? rightRowValue.Values.Count : arguments[2] is SqlConstantExpression { Value : ITuple rightTuple } ? (int?)rightTuple.Length diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStatisticsAggregateMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStatisticsAggregateMethodTranslator.cs index a034f4e95..f902412b5 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStatisticsAggregateMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStatisticsAggregateMethodTranslator.cs @@ -91,7 +91,7 @@ public NpgsqlStatisticsAggregateMethodTranslator( { // These methods accept two enumerable (column) arguments; this is represented in LINQ as a projection from the grouping // to a tuple of the two columns. Since we generally translate tuples to PostgresRowValueExpression, we take it apart here. - if (source.Selector is not PostgresRowValueExpression rowValueExpression) + if (source.Selector is not PgRowValueExpression rowValueExpression) { return null; } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs index 1e4f204e4..c363bbcb5 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs @@ -297,7 +297,7 @@ public NpgsqlStringMethodTranslator(NpgsqlTypeMappingSource typeMappingSource, I { // If the array of strings to be joined is a constant (NewArrayExpression), we translate to concat_ws. // Otherwise we translate to array_to_string, which also supports array columns and parameters. - if (arguments[1] is PostgresNewArrayExpression newArrayExpression) + if (arguments[1] is PgNewArrayExpression newArrayExpression) { var rewrittenArguments = new SqlExpression[newArrayExpression.Expressions.Count + 1]; rewrittenArguments[0] = arguments[0]; diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlTrigramsMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlTrigramsMethodTranslator.cs index 08c441f3a..8e49f5843 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlTrigramsMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlTrigramsMethodTranslator.cs @@ -86,7 +86,7 @@ public NpgsqlTrigramsMethodTranslator( if (BoolReturningOperators.TryGetValue(method, out var boolOperator)) { - return new PostgresUnknownBinaryExpression( + return new PgUnknownBinaryExpression( _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]), _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[2]), boolOperator, @@ -96,7 +96,7 @@ public NpgsqlTrigramsMethodTranslator( if (FloatReturningOperators.TryGetValue(method, out var floatOperator)) { - return new PostgresUnknownBinaryExpression( + return new PgUnknownBinaryExpression( _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]), _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[2]), floatOperator, diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresAllExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgAllExpression.cs similarity index 80% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresAllExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgAllExpression.cs index f78602a68..2bcd33b7c 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresAllExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgAllExpression.cs @@ -6,7 +6,7 @@ /// /// See https://www.postgresql.org/docs/current/static/functions-comparisons.html /// -public class PostgresAllExpression : SqlExpression, IEquatable +public class PgAllExpression : SqlExpression, IEquatable { /// public override Type Type => typeof(bool); @@ -24,19 +24,19 @@ public class PostgresAllExpression : SqlExpression, IEquatable /// The operator. /// - public virtual PostgresAllOperatorType OperatorType { get; } + public virtual PgAllOperatorType OperatorType { get; } /// - /// Constructs a . + /// Constructs a . /// /// The operator symbol to the array expression. /// The value to find. /// The array to search. /// The type mapping for the expression. - public PostgresAllExpression( + public PgAllExpression( SqlExpression item, SqlExpression array, - PostgresAllOperatorType operatorType, + PgAllOperatorType operatorType, RelationalTypeMapping? typeMapping) : base(typeof(bool), typeMapping) { @@ -57,9 +57,9 @@ public PostgresAllExpression( /// The property of the result. /// The property of the result. /// This expression if no children changed, or an expression with the updated children. - public virtual PostgresAllExpression Update(SqlExpression item, SqlExpression array) + public virtual PgAllExpression Update(SqlExpression item, SqlExpression array) => item != Item || array != Array - ? new PostgresAllExpression(item, array, OperatorType, TypeMapping) + ? new PgAllExpression(item, array, OperatorType, TypeMapping) : this; /// @@ -67,10 +67,10 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) => Update((SqlExpression)visitor.Visit(Item), (SqlExpression)visitor.Visit(Array)); /// - public override bool Equals(object? obj) => obj is PostgresAllExpression e && Equals(e); + public override bool Equals(object? obj) => obj is PgAllExpression e && Equals(e); /// - public virtual bool Equals(PostgresAllExpression? other) + public virtual bool Equals(PgAllExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) && @@ -90,8 +90,8 @@ protected override void Print(ExpressionPrinter expressionPrinter) .Append(" ") .Append(OperatorType switch { - PostgresAllOperatorType.Like => "LIKE", - PostgresAllOperatorType.ILike => "ILIKE", + PgAllOperatorType.Like => "LIKE", + PgAllOperatorType.ILike => "ILIKE", _ => throw new ArgumentOutOfRangeException($"Unhandled operator type: {OperatorType}") }) @@ -105,9 +105,9 @@ protected override void Print(ExpressionPrinter expressionPrinter) } /// -/// Determines the operator type for a . +/// Determines the operator type for a . /// -public enum PostgresAllOperatorType +public enum PgAllOperatorType { /// /// Represents a PostgreSQL LIKE ALL operator. diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresAnyExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgAnyExpression.cs similarity index 80% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresAnyExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgAnyExpression.cs index a5a5e9484..6553feeb6 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresAnyExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgAnyExpression.cs @@ -9,7 +9,7 @@ /// /// See https://www.postgresql.org/docs/current/static/functions-comparisons.html /// -public class PostgresAnyExpression : SqlExpression, IEquatable +public class PgAnyExpression : SqlExpression, IEquatable { /// public override Type Type => typeof(bool); @@ -27,19 +27,19 @@ public class PostgresAnyExpression : SqlExpression, IEquatable /// The operator. /// - public virtual PostgresAnyOperatorType OperatorType { get; } + public virtual PgAnyOperatorType OperatorType { get; } /// - /// Constructs a . + /// Constructs a . /// /// The operator symbol to the array expression. /// The value to find. /// The array to search. /// The type mapping for the expression. - public PostgresAnyExpression( + public PgAnyExpression( SqlExpression item, SqlExpression array, - PostgresAnyOperatorType operatorType, + PgAnyOperatorType operatorType, RelationalTypeMapping? typeMapping) : base(typeof(bool), typeMapping) { @@ -50,7 +50,7 @@ public PostgresAnyExpression( throw new ArgumentException("Array expression must be an IEnumerable", nameof(array)); } - if (array is SqlConstantExpression && operatorType == PostgresAnyOperatorType.Equal) + if (array is SqlConstantExpression && operatorType == PgAnyOperatorType.Equal) { throw new ArgumentException($"Use {nameof(InExpression)} for equality against constant arrays", nameof(array)); } @@ -68,9 +68,9 @@ public PostgresAnyExpression( /// The property of the result. /// The property of the result. /// This expression if no children changed, or an expression with the updated children. - public virtual PostgresAnyExpression Update(SqlExpression item, SqlExpression array) + public virtual PgAnyExpression Update(SqlExpression item, SqlExpression array) => item != Item || array != Array - ? new PostgresAnyExpression(item, array, OperatorType, TypeMapping) + ? new PgAnyExpression(item, array, OperatorType, TypeMapping) : this; /// @@ -78,10 +78,10 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) => Update((SqlExpression)visitor.Visit(Item), (SqlExpression)visitor.Visit(Array)); /// - public override bool Equals(object? obj) => obj is PostgresAnyExpression e && Equals(e); + public override bool Equals(object? obj) => obj is PgAnyExpression e && Equals(e); /// - public virtual bool Equals(PostgresAnyExpression? other) + public virtual bool Equals(PgAnyExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) && @@ -101,9 +101,9 @@ protected override void Print(ExpressionPrinter expressionPrinter) .Append(" ") .Append(OperatorType switch { - PostgresAnyOperatorType.Equal => "=", - PostgresAnyOperatorType.Like => "LIKE", - PostgresAnyOperatorType.ILike => "ILIKE", + PgAnyOperatorType.Equal => "=", + PgAnyOperatorType.Like => "LIKE", + PgAnyOperatorType.ILike => "ILIKE", _ => throw new ArgumentOutOfRangeException($"Unhandled operator type: {OperatorType}") }) @@ -117,9 +117,9 @@ protected override void Print(ExpressionPrinter expressionPrinter) } /// -/// Determines the operator type for a . +/// Determines the operator type for a . /// -public enum PostgresAnyOperatorType +public enum PgAnyOperatorType { /// /// Represents a PostgreSQL = ANY operator. diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresArrayIndexExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgArrayIndexExpression.cs similarity index 86% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresArrayIndexExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgArrayIndexExpression.cs index da10be6b8..37d70e012 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresArrayIndexExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgArrayIndexExpression.cs @@ -7,7 +7,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// specifically disallows having an /// of value as arrays are a PostgreSQL-only feature. /// -public class PostgresArrayIndexExpression : SqlExpression, IEquatable +public class PgArrayIndexExpression : SqlExpression, IEquatable { /// /// The array being indexed. @@ -25,14 +25,14 @@ public class PostgresArrayIndexExpression : SqlExpression, IEquatable - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// /// The array tp index into. /// An position in the array to index into. /// Whether the expression is nullable. /// The of the expression. /// The associated with the expression. - public PostgresArrayIndexExpression( + public PgArrayIndexExpression( SqlExpression array, SqlExpression index, bool nullable, @@ -70,17 +70,17 @@ public PostgresArrayIndexExpression( /// The property of the result. /// The property of the result. /// This expression if no children changed, or an expression with the updated children. - public virtual PostgresArrayIndexExpression Update(SqlExpression array, SqlExpression index) + public virtual PgArrayIndexExpression Update(SqlExpression array, SqlExpression index) => array == Array && index == Index ? this - : new PostgresArrayIndexExpression(array, index, IsNullable, Type, TypeMapping); + : new PgArrayIndexExpression(array, index, IsNullable, Type, TypeMapping); /// protected override Expression VisitChildren(ExpressionVisitor visitor) => Update((SqlExpression)visitor.Visit(Array), (SqlExpression)visitor.Visit(Index)); /// - public virtual bool Equals(PostgresArrayIndexExpression? other) + public virtual bool Equals(PgArrayIndexExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) @@ -89,7 +89,7 @@ public virtual bool Equals(PostgresArrayIndexExpression? other) && IsNullable == other.IsNullable; /// - public override bool Equals(object? obj) => obj is PostgresArrayIndexExpression e && Equals(e); + public override bool Equals(object? obj) => obj is PgArrayIndexExpression e && Equals(e); /// public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Array, Index, IsNullable); diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresArraySliceExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgArraySliceExpression.cs similarity index 85% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresArraySliceExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgArraySliceExpression.cs index 9ef587948..1de3e44c6 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresArraySliceExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgArraySliceExpression.cs @@ -6,7 +6,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// /// . /// -public class PostgresArraySliceExpression : SqlExpression, IEquatable +public class PgArraySliceExpression : SqlExpression, IEquatable { /// /// The array being sliced. @@ -29,7 +29,7 @@ public class PostgresArraySliceExpression : SqlExpression, IEquatable - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// /// The array tp slice into. /// The lower bound of the slice. @@ -37,7 +37,7 @@ public class PostgresArraySliceExpression : SqlExpression, IEquatableWhether the expression is nullable. /// The of the expression. /// The associated with the expression. - public PostgresArraySliceExpression( + public PgArraySliceExpression( SqlExpression array, SqlExpression? lowerBound, SqlExpression? upperBound, @@ -67,10 +67,10 @@ public PostgresArraySliceExpression( /// The lower bound of the slice. /// The upper bound of the slice. /// This expression if no children changed, or an expression with the updated children. - public virtual PostgresArraySliceExpression Update(SqlExpression array, SqlExpression? lowerBound, SqlExpression? upperBound) + public virtual PgArraySliceExpression Update(SqlExpression array, SqlExpression? lowerBound, SqlExpression? upperBound) => array == Array && lowerBound == LowerBound && upperBound == UpperBound ? this - : new PostgresArraySliceExpression(array, lowerBound, upperBound, IsNullable, Type, TypeMapping); + : new PgArraySliceExpression(array, lowerBound, upperBound, IsNullable, Type, TypeMapping); /// protected override Expression VisitChildren(ExpressionVisitor visitor) @@ -80,7 +80,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) (SqlExpression?)visitor.Visit(UpperBound)); /// - public virtual bool Equals(PostgresArraySliceExpression? other) + public virtual bool Equals(PgArraySliceExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) @@ -90,7 +90,7 @@ public virtual bool Equals(PostgresArraySliceExpression? other) && IsNullable == other.IsNullable; /// - public override bool Equals(object? obj) => obj is PostgresArraySliceExpression e && Equals(e); + public override bool Equals(object? obj) => obj is PgArraySliceExpression e && Equals(e); /// public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Array, LowerBound, UpperBound); diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgBinaryExpression.cs similarity index 63% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgBinaryExpression.cs index 1c28089e1..755cd0b4b 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgBinaryExpression.cs @@ -5,18 +5,18 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// /// An expression that represents a PostgreSQL-specific binary operation in a SQL tree. /// -public class PostgresBinaryExpression : SqlExpression +public class PgBinaryExpression : SqlExpression { /// - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// /// The operator to apply. /// An expression which is left operand. /// An expression which is right operand. /// The of the expression. /// The associated with the expression. - public PostgresBinaryExpression( - PostgresExpressionType operatorType, + public PgBinaryExpression( + PgExpressionType operatorType, SqlExpression left, SqlExpression right, Type type, @@ -34,7 +34,7 @@ public PostgresBinaryExpression( /// /// The operator of this PostgreSQL binary operation. /// - public virtual PostgresExpressionType OperatorType { get; } + public virtual PgExpressionType OperatorType { get; } /// /// The left operand. /// @@ -62,13 +62,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// The property of the result. /// This expression if no children changed, or an expression with the updated children. - public virtual PostgresBinaryExpression Update(SqlExpression left, SqlExpression right) + public virtual PgBinaryExpression Update(SqlExpression left, SqlExpression right) { Check.NotNull(left, nameof(left)); Check.NotNull(right, nameof(right)); return left != Left || right != Right - ? new PostgresBinaryExpression(OperatorType, left, right, Type, TypeMapping) + ? new PgBinaryExpression(OperatorType, left, right, Type, TypeMapping) : this; } @@ -95,46 +95,46 @@ protected override void Print(ExpressionPrinter expressionPrinter) .Append(" ") .Append(OperatorType switch { - PostgresExpressionType.Contains => "@>", - PostgresExpressionType.ContainedBy => "<@", - PostgresExpressionType.Overlaps => "&&", - - PostgresExpressionType.NetworkContainedByOrEqual => "<<=", - PostgresExpressionType.NetworkContainsOrEqual => ">>=", - PostgresExpressionType.NetworkContainsOrContainedBy => "&&", - - PostgresExpressionType.RangeIsStrictlyLeftOf => "<<", - PostgresExpressionType.RangeIsStrictlyRightOf => ">>", - PostgresExpressionType.RangeDoesNotExtendRightOf => "&<", - PostgresExpressionType.RangeDoesNotExtendLeftOf => "&>", - PostgresExpressionType.RangeIsAdjacentTo => "-|-", - PostgresExpressionType.RangeUnion => "+", - PostgresExpressionType.RangeIntersect => "*", - PostgresExpressionType.RangeExcept => "-", - - PostgresExpressionType.TextSearchMatch => "@@", - PostgresExpressionType.TextSearchAnd => "&&", - PostgresExpressionType.TextSearchOr => "||", - - PostgresExpressionType.JsonExists => "?", - PostgresExpressionType.JsonExistsAny => "?|", - PostgresExpressionType.JsonExistsAll => "?&", - - PostgresExpressionType.LTreeMatches + PgExpressionType.Contains => "@>", + PgExpressionType.ContainedBy => "<@", + PgExpressionType.Overlaps => "&&", + + PgExpressionType.NetworkContainedByOrEqual => "<<=", + PgExpressionType.NetworkContainsOrEqual => ">>=", + PgExpressionType.NetworkContainsOrContainedBy => "&&", + + PgExpressionType.RangeIsStrictlyLeftOf => "<<", + PgExpressionType.RangeIsStrictlyRightOf => ">>", + PgExpressionType.RangeDoesNotExtendRightOf => "&<", + PgExpressionType.RangeDoesNotExtendLeftOf => "&>", + PgExpressionType.RangeIsAdjacentTo => "-|-", + PgExpressionType.RangeUnion => "+", + PgExpressionType.RangeIntersect => "*", + PgExpressionType.RangeExcept => "-", + + PgExpressionType.TextSearchMatch => "@@", + PgExpressionType.TextSearchAnd => "&&", + PgExpressionType.TextSearchOr => "||", + + PgExpressionType.JsonExists => "?", + PgExpressionType.JsonExistsAny => "?|", + PgExpressionType.JsonExistsAll => "?&", + + PgExpressionType.LTreeMatches when Right.TypeMapping?.StoreType == "lquery" || Right.TypeMapping is NpgsqlArrayTypeMapping { ElementTypeMapping.StoreType: "lquery" } => "~", - PostgresExpressionType.LTreeMatches + PgExpressionType.LTreeMatches when Right.TypeMapping?.StoreType == "ltxtquery" => "@", - PostgresExpressionType.LTreeMatchesAny => "?", - PostgresExpressionType.LTreeFirstAncestor => "?@>", - PostgresExpressionType.LTreeFirstDescendent => "?<@", - PostgresExpressionType.LTreeFirstMatches + PgExpressionType.LTreeMatchesAny => "?", + PgExpressionType.LTreeFirstAncestor => "?@>", + PgExpressionType.LTreeFirstDescendent => "?<@", + PgExpressionType.LTreeFirstMatches when Right.TypeMapping?.StoreType == "lquery" => "?~", - PostgresExpressionType.LTreeFirstMatches + PgExpressionType.LTreeFirstMatches when Right.TypeMapping?.StoreType == "ltxtquery" => "?@", - PostgresExpressionType.Distance => "<->", + PgExpressionType.Distance => "<->", _ => throw new ArgumentOutOfRangeException($"Unhandled operator type: {OperatorType}") }) @@ -154,17 +154,17 @@ protected override void Print(ExpressionPrinter expressionPrinter) expressionPrinter.Append(")"); } - static bool RequiresBrackets(SqlExpression expression) => expression is PostgresBinaryExpression or LikeExpression; + static bool RequiresBrackets(SqlExpression expression) => expression is PgBinaryExpression or LikeExpression; } /// public override bool Equals(object? obj) => obj is not null && (ReferenceEquals(this, obj) - || obj is PostgresBinaryExpression sqlBinaryExpression + || obj is PgBinaryExpression sqlBinaryExpression && Equals(sqlBinaryExpression)); - private bool Equals(PostgresBinaryExpression sqlBinaryExpression) + private bool Equals(PgBinaryExpression sqlBinaryExpression) => base.Equals(sqlBinaryExpression) && OperatorType == sqlBinaryExpression.OperatorType && Left.Equals(sqlBinaryExpression.Left) diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresDeleteExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgDeleteExpression.cs similarity index 86% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresDeleteExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgDeleteExpression.cs index 62e5090b8..ef2073581 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresDeleteExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgDeleteExpression.cs @@ -3,7 +3,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// /// An SQL expression that represents a PostgreSQL DELETE operation. /// -public sealed class PostgresDeleteExpression : Expression, IPrintableExpression +public sealed class PgDeleteExpression : Expression, IPrintableExpression { /// /// The tables that rows are to be deleted from. @@ -26,9 +26,9 @@ public sealed class PostgresDeleteExpression : Expression, IPrintableExpression public ISet Tags { get; } /// - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// - public PostgresDeleteExpression( + public PgDeleteExpression( TableExpression table, IReadOnlyList fromItems, SqlExpression? predicate, @@ -54,10 +54,10 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// return this expression. /// /// The property of the result. - public PostgresDeleteExpression Update(SqlExpression? predicate) + public PgDeleteExpression Update(SqlExpression? predicate) => predicate == Predicate ? this - : new PostgresDeleteExpression(Table, FromItems, predicate, Tags); + : new PgDeleteExpression(Table, FromItems, predicate, Tags); /// public void Print(ExpressionPrinter expressionPrinter) @@ -94,10 +94,10 @@ public void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object? obj) => obj != null && (ReferenceEquals(this, obj) - || obj is PostgresDeleteExpression pgDeleteExpression + || obj is PgDeleteExpression pgDeleteExpression && Equals(pgDeleteExpression)); - private bool Equals(PostgresDeleteExpression pgDeleteExpression) + private bool Equals(PgDeleteExpression pgDeleteExpression) => Table == pgDeleteExpression.Table && FromItems.SequenceEqual(pgDeleteExpression.FromItems) && (Predicate is null ? pgDeleteExpression.Predicate is null : Predicate.Equals(pgDeleteExpression.Predicate)); diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresFunctionExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgFunctionExpression.cs similarity index 91% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresFunctionExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgFunctionExpression.cs index 87bb0fa21..d0bc82472 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresFunctionExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgFunctionExpression.cs @@ -7,7 +7,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// (e.g. make_interval(weeks => 2) and non-comma parameter separators (e.g. position(substring in string)). /// [DebuggerDisplay("{" + nameof(ToString) + "()}")] -public class PostgresFunctionExpression : SqlFunctionExpression, IEquatable +public class PgFunctionExpression : SqlFunctionExpression, IEquatable { /// public new virtual IReadOnlyList Arguments @@ -46,9 +46,9 @@ public class PostgresFunctionExpression : SqlFunctionExpression, IEquatable ArgumentSeparators { get; } /// - /// Creates an instance of with named arguments. + /// Creates an instance of with named arguments. /// - public static PostgresFunctionExpression CreateWithNamedArguments( + public static PgFunctionExpression CreateWithNamedArguments( string name, IEnumerable arguments, IEnumerable argumentNames, @@ -61,16 +61,16 @@ public static PostgresFunctionExpression CreateWithNamedArguments( Check.NotNull(arguments, nameof(arguments)); Check.NotNull(argumentNames, nameof(argumentNames)); - return new PostgresFunctionExpression( + return new PgFunctionExpression( name, arguments, argumentNames, argumentSeparators: null, aggregateDistinct: false, aggregatePredicate: null, aggregateOrderings: Array.Empty(), nullable: nullable, argumentsPropagateNullability: argumentsPropagateNullability, type: type, typeMapping: typeMapping); } /// - /// Creates an instance of with argument separators. + /// Creates an instance of with argument separators. /// - public static PostgresFunctionExpression CreateWithArgumentSeparators( + public static PgFunctionExpression CreateWithArgumentSeparators( string name, IEnumerable arguments, IEnumerable argumentSeparators, @@ -83,16 +83,16 @@ public static PostgresFunctionExpression CreateWithArgumentSeparators( Check.NotNull(arguments, nameof(arguments)); Check.NotNull(argumentSeparators, nameof(argumentSeparators)); - return new PostgresFunctionExpression( + return new PgFunctionExpression( name, arguments, argumentNames: null, argumentSeparators: argumentSeparators, aggregateDistinct: false, aggregatePredicate: null, aggregateOrderings: Array.Empty(), nullable: nullable, argumentsPropagateNullability: argumentsPropagateNullability, type: type, typeMapping: typeMapping); } /// - /// Creates a new instance of . + /// Creates a new instance of . /// - public PostgresFunctionExpression( + public PgFunctionExpression( string name, IEnumerable arguments, IEnumerable? argumentNames, @@ -183,7 +183,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) } return changed - ? new PostgresFunctionExpression( + ? new PgFunctionExpression( Name, visitedArguments ?? Arguments, ArgumentNames, ArgumentSeparators, IsAggregateDistinct, visitedAggregatePredicate ?? AggregatePredicate, @@ -194,7 +194,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// public override SqlFunctionExpression ApplyTypeMapping(RelationalTypeMapping? typeMapping) - => new PostgresFunctionExpression( + => new PgFunctionExpression( Name, Arguments, ArgumentNames, @@ -216,7 +216,7 @@ public override SqlFunctionExpression Update(SqlExpression? instance, IReadOnlyL } return !arguments.SequenceEqual(Arguments) - ? new PostgresFunctionExpression( + ? new PgFunctionExpression( Name, arguments, ArgumentNames, ArgumentSeparators, IsAggregateDistinct, AggregatePredicate, @@ -229,12 +229,12 @@ public override SqlFunctionExpression Update(SqlExpression? instance, IReadOnlyL /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// - public virtual PostgresFunctionExpression UpdateAggregateComponents( + public virtual PgFunctionExpression UpdateAggregateComponents( SqlExpression? predicate, IReadOnlyList orderings) { return predicate != AggregatePredicate || orderings != AggregateOrderings - ? new PostgresFunctionExpression( + ? new PgFunctionExpression( Name, Arguments, ArgumentNames, ArgumentSeparators, IsAggregateDistinct, predicate, @@ -287,10 +287,10 @@ protected override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object? obj) - => obj is PostgresFunctionExpression pgFunction && Equals(pgFunction); + => obj is PgFunctionExpression pgFunction && Equals(pgFunction); /// - public virtual bool Equals(PostgresFunctionExpression? other) + public virtual bool Equals(PgFunctionExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresILikeExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgILikeExpression.cs similarity index 85% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresILikeExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgILikeExpression.cs index e56b01be5..1e84bc3f8 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresILikeExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgILikeExpression.cs @@ -4,7 +4,7 @@ /// Represents a PostgreSQL ILIKE expression. /// // ReSharper disable once InconsistentNaming -public class PostgresILikeExpression : SqlExpression, IEquatable +public class PgILikeExpression : SqlExpression, IEquatable { /// /// The match expression. @@ -22,14 +22,14 @@ public class PostgresILikeExpression : SqlExpression, IEquatable - /// Constructs a . + /// Constructs a . /// /// The expression to match. /// The pattern to match. /// The escape character to use in . /// The associated with the expression. /// - public PostgresILikeExpression( + public PgILikeExpression( SqlExpression match, SqlExpression pattern, SqlExpression? escapeChar, @@ -52,19 +52,19 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// - public virtual PostgresILikeExpression Update( + public virtual PgILikeExpression Update( SqlExpression match, SqlExpression pattern, SqlExpression? escapeChar) => match == Match && pattern == Pattern && escapeChar == EscapeChar ? this - : new PostgresILikeExpression(match, pattern, escapeChar, TypeMapping); + : new PgILikeExpression(match, pattern, escapeChar, TypeMapping); /// - public override bool Equals(object? obj) => obj is PostgresILikeExpression other && Equals(other); + public override bool Equals(object? obj) => obj is PgILikeExpression other && Equals(other); /// - public virtual bool Equals(PostgresILikeExpression? other) + public virtual bool Equals(PgILikeExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) && diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresJsonTraversalExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgJsonTraversalExpression.cs similarity index 78% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresJsonTraversalExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgJsonTraversalExpression.cs index cb02e7477..ad544b301 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresJsonTraversalExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgJsonTraversalExpression.cs @@ -3,7 +3,7 @@ /// /// Represents a PostgreSQL JSON operator traversing a JSON document with a path (i.e. x#>y or x#>>y) /// -public class PostgresJsonTraversalExpression : SqlExpression, IEquatable +public class PgJsonTraversalExpression : SqlExpression, IEquatable { /// /// The match expression. @@ -21,9 +21,9 @@ public class PostgresJsonTraversalExpression : SqlExpression, IEquatable - /// Constructs a . + /// Constructs a . /// - public PostgresJsonTraversalExpression( + public PgJsonTraversalExpression( SqlExpression expression, IReadOnlyList path, bool returnsText, @@ -51,17 +51,17 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// - public virtual PostgresJsonTraversalExpression Update(SqlExpression expression, IReadOnlyList path) + public virtual PgJsonTraversalExpression Update(SqlExpression expression, IReadOnlyList path) => expression == Expression && path.Count == Path.Count && path.Zip(Path, (x, y) => (x, y)).All(tup => tup.x == tup.y) ? this - : new PostgresJsonTraversalExpression(expression, path, ReturnsText, Type, TypeMapping); + : new PgJsonTraversalExpression(expression, path, ReturnsText, Type, TypeMapping); /// - /// Appends an additional path component to this and returns the result. + /// Appends an additional path component to this and returns the result. /// - public virtual PostgresJsonTraversalExpression Append(SqlExpression pathComponent) + public virtual PgJsonTraversalExpression Append(SqlExpression pathComponent) { var newPath = new SqlExpression[Path.Count + 1]; for (var i = 0; i < Path.Count(); i++) @@ -70,14 +70,14 @@ public virtual PostgresJsonTraversalExpression Append(SqlExpression pathComponen } newPath[newPath.Length - 1] = pathComponent; - return new PostgresJsonTraversalExpression(Expression, newPath, ReturnsText, Type, TypeMapping); + return new PgJsonTraversalExpression(Expression, newPath, ReturnsText, Type, TypeMapping); } /// - public override bool Equals(object? obj) => Equals(obj as PostgresJsonTraversalExpression); + public override bool Equals(object? obj) => Equals(obj as PgJsonTraversalExpression); /// - public virtual bool Equals(PostgresJsonTraversalExpression? other) + public virtual bool Equals(PgJsonTraversalExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) && diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresNewArrayExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgNewArrayExpression.cs similarity index 80% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresNewArrayExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgNewArrayExpression.cs index d722539bd..7e4edfb38 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresNewArrayExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgNewArrayExpression.cs @@ -3,15 +3,15 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// /// Represents creating a new PostgreSQL array. /// -public class PostgresNewArrayExpression : SqlExpression +public class PgNewArrayExpression : SqlExpression { /// - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// /// The values to initialize the elements of the new array. /// The of the expression. /// The associated with the expression. - public PostgresNewArrayExpression( + public PgNewArrayExpression( IReadOnlyList expressions, Type type, RelationalTypeMapping? typeMapping) @@ -21,7 +21,7 @@ public PostgresNewArrayExpression( if (!type.IsArrayOrGenericList()) { - throw new ArgumentException($"{nameof(PostgresNewArrayExpression)} must have an array type"); + throw new ArgumentException($"{nameof(PgNewArrayExpression)} must have an array type"); } Expressions = expressions; @@ -56,7 +56,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) return newExpressions is null ? this - : new PostgresNewArrayExpression(newExpressions, Type, TypeMapping); + : new PgNewArrayExpression(newExpressions, Type, TypeMapping); } /// @@ -65,13 +65,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// /// The values to initialize the elements of the new array. /// This expression if no children changed, or an expression with the updated children. - public virtual PostgresNewArrayExpression Update(IReadOnlyList expressions) + public virtual PgNewArrayExpression Update(IReadOnlyList expressions) { Check.NotNull(expressions, nameof(expressions)); return expressions == Expressions ? this - : new PostgresNewArrayExpression(expressions, Type, TypeMapping); + : new PgNewArrayExpression(expressions, Type, TypeMapping); } /// @@ -101,12 +101,12 @@ protected override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object? obj) => obj is not null && (ReferenceEquals(this, obj) - || obj is PostgresNewArrayExpression sqlBinaryExpression + || obj is PgNewArrayExpression sqlBinaryExpression && Equals(sqlBinaryExpression)); - private bool Equals(PostgresNewArrayExpression postgresNewArrayExpression) - => base.Equals(postgresNewArrayExpression) - && Expressions.SequenceEqual(postgresNewArrayExpression.Expressions); + private bool Equals(PgNewArrayExpression pgNewArrayExpression) + => base.Equals(pgNewArrayExpression) + && Expressions.SequenceEqual(pgNewArrayExpression.Expressions); /// public override int GetHashCode() @@ -121,4 +121,4 @@ public override int GetHashCode() return hash.ToHashCode(); } -} \ No newline at end of file +} diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresRegexMatchExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgRegexMatchExpression.cs similarity index 82% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresRegexMatchExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgRegexMatchExpression.cs index c5c2dc0e5..eeda00161 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresRegexMatchExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgRegexMatchExpression.cs @@ -5,7 +5,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// /// Represents a PostgreSQL regular expression match expression. /// -public class PostgresRegexMatchExpression : SqlExpression, IEquatable +public class PgRegexMatchExpression : SqlExpression, IEquatable { /// public override Type Type => typeof(bool); @@ -26,13 +26,13 @@ public class PostgresRegexMatchExpression : SqlExpression, IEquatable - /// Constructs a . + /// Constructs a . /// /// The expression to match. /// The pattern to match. /// The options for regular expression evaluation. /// The type mapping for the expression. - public PostgresRegexMatchExpression( + public PgRegexMatchExpression( SqlExpression match, SqlExpression pattern, RegexOptions options, @@ -52,13 +52,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// - public virtual PostgresRegexMatchExpression Update(SqlExpression match, SqlExpression pattern) + public virtual PgRegexMatchExpression Update(SqlExpression match, SqlExpression pattern) => match != Match || pattern != Pattern - ? new PostgresRegexMatchExpression(match, pattern, Options, TypeMapping) + ? new PgRegexMatchExpression(match, pattern, Options, TypeMapping) : this; /// - public virtual bool Equals(PostgresRegexMatchExpression? other) + public virtual bool Equals(PgRegexMatchExpression? other) => ReferenceEquals(this, other) || other is not null && base.Equals(other) && @@ -68,7 +68,7 @@ other is not null && /// public override bool Equals(object? other) - => other is PostgresRegexMatchExpression otherRegexMatch && Equals(otherRegexMatch); + => other is PgRegexMatchExpression otherRegexMatch && Equals(otherRegexMatch); /// public override int GetHashCode() diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresRowValueExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgRowValueExpression.cs similarity index 84% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresRowValueExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgRowValueExpression.cs index 0ee7e7ff1..65b97effd 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresRowValueExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgRowValueExpression.cs @@ -12,7 +12,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// See the PostgreSQL docs /// for more information. /// -public class PostgresRowValueExpression : SqlExpression, IEquatable +public class PgRowValueExpression : SqlExpression, IEquatable { /// /// The values of this PostgreSQL row value expression. @@ -20,7 +20,7 @@ public class PostgresRowValueExpression : SqlExpression, IEquatable Values { get; } /// - public PostgresRowValueExpression(IReadOnlyList values, Type type, RelationalTypeMapping? typeMapping = null) + public PgRowValueExpression(IReadOnlyList values, Type type, RelationalTypeMapping? typeMapping = null) : base(type, typeMapping) { Check.NotNull(values, nameof(values)); @@ -55,17 +55,17 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) } } - return newRowValues is null ? this : new PostgresRowValueExpression(newRowValues, Type); + return newRowValues is null ? this : new PgRowValueExpression(newRowValues, Type); } /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// - public virtual PostgresRowValueExpression Update(IReadOnlyList values) + public virtual PgRowValueExpression Update(IReadOnlyList values) => values.Count == Values.Count && values.Zip(Values, (x, y) => (x, y)).All(tup => tup.x == tup.y) ? this - : new PostgresRowValueExpression(values, Type); + : new PgRowValueExpression(values, Type); /// protected override void Print(ExpressionPrinter expressionPrinter) @@ -88,10 +88,10 @@ protected override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object? obj) - => obj is PostgresRowValueExpression other && Equals(other); + => obj is PgRowValueExpression other && Equals(other); /// - public virtual bool Equals(PostgresRowValueExpression? other) + public virtual bool Equals(PgRowValueExpression? other) { if (other is null || !base.Equals(other) || other.Values.Count != Values.Count) { diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresUnknownBinaryExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgUnknownBinaryExpression.cs similarity index 83% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresUnknownBinaryExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgUnknownBinaryExpression.cs index 8c75f526b..6cb9b7759 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresUnknownBinaryExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgUnknownBinaryExpression.cs @@ -7,7 +7,7 @@ /// All type mappings must be applied to the operands before the expression is constructed, since there's /// no inference logic for it in . /// -public class PostgresUnknownBinaryExpression : SqlExpression, IEquatable +public class PgUnknownBinaryExpression : SqlExpression, IEquatable { /// /// The left-hand expression. @@ -25,7 +25,7 @@ public class PostgresUnknownBinaryExpression : SqlExpression, IEquatable - /// Constructs a . + /// Constructs a . /// /// The left-hand expression. /// The right-hand expression. @@ -33,7 +33,7 @@ public class PostgresUnknownBinaryExpression : SqlExpression, IEquatableThe result type. /// The type mapping for the expression. /// - public PostgresUnknownBinaryExpression( + public PgUnknownBinaryExpression( SqlExpression left, SqlExpression right, string binaryOperator, @@ -54,13 +54,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// - public virtual PostgresUnknownBinaryExpression Update(SqlExpression left, SqlExpression right) + public virtual PgUnknownBinaryExpression Update(SqlExpression left, SqlExpression right) => left == Left && right == Right ? this - : new PostgresUnknownBinaryExpression(left, right, Operator, Type, TypeMapping); + : new PgUnknownBinaryExpression(left, right, Operator, Type, TypeMapping); /// - public virtual bool Equals(PostgresUnknownBinaryExpression? other) + public virtual bool Equals(PgUnknownBinaryExpression? other) => ReferenceEquals(this, other) || other is not null && Left.Equals(other.Left) && @@ -68,7 +68,7 @@ other is not null && Operator == other.Operator; /// - public override bool Equals(object? obj) => obj is PostgresUnknownBinaryExpression e && Equals(e); + public override bool Equals(object? obj) => obj is PgUnknownBinaryExpression e && Equals(e); /// public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Left, Right, Operator); diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresUnnestExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PgUnnestExpression.cs similarity index 92% rename from src/EFCore.PG/Query/Expressions/Internal/PostgresUnnestExpression.cs rename to src/EFCore.PG/Query/Expressions/Internal/PgUnnestExpression.cs index 34bfd6a49..b85910162 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresUnnestExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PgUnnestExpression.cs @@ -21,7 +21,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// -public class PostgresUnnestExpression : TableValuedFunctionExpression +public class PgUnnestExpression : TableValuedFunctionExpression { /// /// The array to be un-nested into a table. @@ -63,7 +63,7 @@ public virtual SqlExpression Array /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public PostgresUnnestExpression(string alias, SqlExpression array, string columnName, bool withOrdinality = true) + public PgUnnestExpression(string alias, SqlExpression array, string columnName, bool withOrdinality = true) : base(alias, "unnest", schema: null, builtIn: true, new[] { array }) { ColumnName = columnName; @@ -87,10 +87,10 @@ public override TableValuedFunctionExpression Update(IReadOnlyList /// The property of the result. /// This expression if no children changed, or an expression with the updated children. - public virtual PostgresUnnestExpression Update(SqlExpression array) + public virtual PgUnnestExpression Update(SqlExpression array) => array == Array ? this - : new PostgresUnnestExpression(Alias, array, ColumnName, WithOrdinality); + : new PgUnnestExpression(Alias, array, ColumnName, WithOrdinality); /// protected override void Print(ExpressionPrinter expressionPrinter) @@ -119,10 +119,10 @@ protected override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object? obj) => obj != null && (ReferenceEquals(this, obj) - || obj is PostgresUnnestExpression unnestExpression + || obj is PgUnnestExpression unnestExpression && Equals(unnestExpression)); - private bool Equals(PostgresUnnestExpression unnestExpression) + private bool Equals(PgUnnestExpression unnestExpression) => base.Equals(unnestExpression) && ColumnName == unnestExpression.ColumnName && WithOrdinality == unnestExpression.WithOrdinality; diff --git a/src/EFCore.PG/Query/Expressions/PostgresExpressionType.cs b/src/EFCore.PG/Query/Expressions/PgExpressionType.cs similarity index 98% rename from src/EFCore.PG/Query/Expressions/PostgresExpressionType.cs rename to src/EFCore.PG/Query/Expressions/PgExpressionType.cs index 967b3b1aa..2311326ff 100644 --- a/src/EFCore.PG/Query/Expressions/PostgresExpressionType.cs +++ b/src/EFCore.PG/Query/Expressions/PgExpressionType.cs @@ -3,7 +3,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions; /// /// PostgreSQL-specific expression node types. /// -public enum PostgresExpressionType +public enum PgExpressionType { #region General operators @@ -11,7 +11,7 @@ public enum PostgresExpressionType /// Represents a PostgreSQL contains operator. /// Contains, // >> (inet/cidr), @> - + /// /// Represents a PostgreSQL contained-by operator. /// @@ -36,12 +36,12 @@ public enum PostgresExpressionType /// Represents a PostgreSQL network contained-by-or-equal operator. /// NetworkContainedByOrEqual, // <<= - + /// /// Represents a PostgreSQL network contains-or-equal operator. /// NetworkContainsOrEqual, // >>= - + /// /// Represents a PostgreSQL network contains-or-contained-by operator. /// @@ -55,12 +55,12 @@ public enum PostgresExpressionType /// Represents a PostgreSQL operator for checking if a range is strictly to the left of another range. /// RangeIsStrictlyLeftOf, // << - + /// /// Represents a PostgreSQL operator for checking if a range is strictly to the right of another range. /// RangeIsStrictlyRightOf, // >> - + /// /// Represents a PostgreSQL operator for checking if a range does not extend to the right of another range. /// @@ -75,17 +75,17 @@ public enum PostgresExpressionType /// Represents a PostgreSQL operator for checking if a range is adjacent to another range. /// RangeIsAdjacentTo, // -|- - + /// /// Represents a PostgreSQL operator for performing a union between two ranges. /// RangeUnion, // + - + /// /// Represents a PostgreSQL operator for performing an intersection between two ranges. /// RangeIntersect, // * - + /// /// Represents a PostgreSQL operator for performing an except operation between two ranges. /// @@ -104,7 +104,7 @@ public enum PostgresExpressionType /// Represents a PostgreSQL operator for logical AND within a full-text search match. /// TextSearchAnd, // && - + /// /// Represents a PostgreSQL operator for logical OR within a full-text search match. /// @@ -123,7 +123,7 @@ public enum PostgresExpressionType /// Represents a PostgreSQL operator for checking whether any of multiple keys exists in a JSON document. /// JsonExistsAny, // ?@> - + /// /// Represents a PostgreSQL operator for checking whether all the given keys exist in a JSON document. /// @@ -132,7 +132,7 @@ public enum PostgresExpressionType #endregion JSON #region LTree - + /// /// Represents a PostgreSQL operator for matching in an ltree type. /// @@ -142,7 +142,7 @@ public enum PostgresExpressionType /// Represents a PostgreSQL operator for matching in an ltree type. /// LTreeMatchesAny, // ? - + /// /// Represents a PostgreSQL operator for finding the first ancestor in an ltree type. /// @@ -152,7 +152,7 @@ public enum PostgresExpressionType /// Represents a PostgreSQL operator for finding the first descendent in an ltree type. /// LTreeFirstDescendent, // ?<@ - + /// /// Represents a PostgreSQL operator for finding the first match in an ltree type. /// diff --git a/src/EFCore.PG/Query/Internal/NpgsqlDeleteConvertingExpressionVisitor.cs b/src/EFCore.PG/Query/Internal/NpgsqlDeleteConvertingExpressionVisitor.cs index f387978f0..cf7a4f7b5 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlDeleteConvertingExpressionVisitor.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlDeleteConvertingExpressionVisitor.cs @@ -3,7 +3,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal; /// -/// Converts the relational into a PG-specific , which +/// Converts the relational into a PG-specific , which /// precisely models a DELETE statement in PostgreSQL. This is done to handle the PG-specific USING syntax for table joining. /// public class NpgsqlDeleteConvertingExpressionVisitor : ExpressionVisitor @@ -93,6 +93,6 @@ protected virtual Expression VisitDelete(DeleteExpression deleteExpression) ExpressionType.AndAlso, joinPredicates, selectExpression.Predicate, typeof(bool), joinPredicates.TypeMapping) }; - return new PostgresDeleteExpression(deleteExpression.Table, fromItems, predicate, deleteExpression.Tags); + return new PgDeleteExpression(deleteExpression.Table, fromItems, predicate, deleteExpression.Tags); } } diff --git a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs index 876e566b9..d657c6a10 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs @@ -47,20 +47,20 @@ public NpgsqlQuerySqlGenerator( protected override Expression VisitExtension(Expression extensionExpression) => extensionExpression switch { - PostgresAllExpression e => VisitArrayAll(e), - PostgresAnyExpression e => VisitArrayAny(e), - PostgresArrayIndexExpression e => VisitArrayIndex(e), - PostgresArraySliceExpression e => VisitArraySlice(e), - PostgresBinaryExpression e => VisitPostgresBinary(e), - PostgresDeleteExpression e => VisitPostgresDelete(e), - PostgresFunctionExpression e => VisitPostgresFunction(e), - PostgresILikeExpression e => VisitILike(e), - PostgresJsonTraversalExpression e => VisitJsonPathTraversal(e), - PostgresNewArrayExpression e => VisitPostgresNewArray(e), - PostgresRegexMatchExpression e => VisitRegexMatch(e), - PostgresRowValueExpression e => VisitRowValue(e), - PostgresUnknownBinaryExpression e => VisitUnknownBinary(e), - PostgresUnnestExpression e => VisitUnnestExpression(e), + PgAllExpression e => VisitArrayAll(e), + PgAnyExpression e => VisitArrayAny(e), + PgArrayIndexExpression e => VisitArrayIndex(e), + PgArraySliceExpression e => VisitArraySlice(e), + PgBinaryExpression e => VisitPostgresBinary(e), + PgDeleteExpression e => VisitPostgresDelete(e), + PgFunctionExpression e => VisitPostgresFunction(e), + PgILikeExpression e => VisitILike(e), + PgJsonTraversalExpression e => VisitJsonPathTraversal(e), + PgNewArrayExpression e => VisitPostgresNewArray(e), + PgRegexMatchExpression e => VisitRegexMatch(e), + PgRowValueExpression e => VisitRowValue(e), + PgUnknownBinaryExpression e => VisitUnknownBinary(e), + PgUnnestExpression e => VisitUnnestExpression(e), _ => base.VisitExtension(extensionExpression) }; @@ -69,7 +69,7 @@ protected override void GenerateRootCommand(Expression queryExpression) { switch (queryExpression) { - case PostgresDeleteExpression postgresDeleteExpression: + case PgDeleteExpression postgresDeleteExpression: GenerateTagsHeaderComment(postgresDeleteExpression.Tags); VisitPostgresDelete(postgresDeleteExpression); break; @@ -256,7 +256,7 @@ protected override Expression VisitDelete(DeleteExpression deleteExpression) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual Expression VisitPostgresDelete(PostgresDeleteExpression pgDeleteExpression) + protected virtual Expression VisitPostgresDelete(PgDeleteExpression pgDeleteExpression) { Sql.Append("DELETE FROM "); Visit(pgDeleteExpression.Table); @@ -407,13 +407,13 @@ void LiftPredicate(TableExpressionBase joinTable) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual Expression VisitPostgresNewArray(PostgresNewArrayExpression postgresNewArrayExpression) + protected virtual Expression VisitPostgresNewArray(PgNewArrayExpression pgNewArrayExpression) { - Debug.Assert(postgresNewArrayExpression.TypeMapping is not null); + Debug.Assert(pgNewArrayExpression.TypeMapping is not null); Sql.Append("ARRAY["); var first = true; - foreach (var initializer in postgresNewArrayExpression.Expressions) + foreach (var initializer in pgNewArrayExpression.Expressions) { if (!first) { @@ -427,9 +427,9 @@ protected virtual Expression VisitPostgresNewArray(PostgresNewArrayExpression po // Not sure if the explicit store type is necessary, but just to be sure. Sql .Append("]::") - .Append(postgresNewArrayExpression.TypeMapping.StoreType); + .Append(pgNewArrayExpression.TypeMapping.StoreType); - return postgresNewArrayExpression; + return pgNewArrayExpression; } /// @@ -438,7 +438,7 @@ protected virtual Expression VisitPostgresNewArray(PostgresNewArrayExpression po /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual Expression VisitPostgresBinary(PostgresBinaryExpression binaryExpression) + protected virtual Expression VisitPostgresBinary(PgBinaryExpression binaryExpression) { Check.NotNull(binaryExpression, nameof(binaryExpression)); @@ -463,54 +463,54 @@ protected virtual Expression VisitPostgresBinary(PostgresBinaryExpression binary .Append(" ") .Append(binaryExpression.OperatorType switch { - PostgresExpressionType.Contains + PgExpressionType.Contains when binaryExpression.Left.TypeMapping is NpgsqlInetTypeMapping or NpgsqlCidrTypeMapping => ">>", - PostgresExpressionType.ContainedBy + PgExpressionType.ContainedBy when binaryExpression.Left.TypeMapping is NpgsqlInetTypeMapping or NpgsqlCidrTypeMapping => "<<", - PostgresExpressionType.Contains => "@>", - PostgresExpressionType.ContainedBy => "<@", - PostgresExpressionType.Overlaps => "&&", + PgExpressionType.Contains => "@>", + PgExpressionType.ContainedBy => "<@", + PgExpressionType.Overlaps => "&&", - PostgresExpressionType.NetworkContainedByOrEqual => "<<=", - PostgresExpressionType.NetworkContainsOrEqual => ">>=", - PostgresExpressionType.NetworkContainsOrContainedBy => "&&", + PgExpressionType.NetworkContainedByOrEqual => "<<=", + PgExpressionType.NetworkContainsOrEqual => ">>=", + PgExpressionType.NetworkContainsOrContainedBy => "&&", - PostgresExpressionType.RangeIsStrictlyLeftOf => "<<", - PostgresExpressionType.RangeIsStrictlyRightOf => ">>", - PostgresExpressionType.RangeDoesNotExtendRightOf => "&<", - PostgresExpressionType.RangeDoesNotExtendLeftOf => "&>", - PostgresExpressionType.RangeIsAdjacentTo => "-|-", - PostgresExpressionType.RangeUnion => "+", - PostgresExpressionType.RangeIntersect => "*", - PostgresExpressionType.RangeExcept => "-", + PgExpressionType.RangeIsStrictlyLeftOf => "<<", + PgExpressionType.RangeIsStrictlyRightOf => ">>", + PgExpressionType.RangeDoesNotExtendRightOf => "&<", + PgExpressionType.RangeDoesNotExtendLeftOf => "&>", + PgExpressionType.RangeIsAdjacentTo => "-|-", + PgExpressionType.RangeUnion => "+", + PgExpressionType.RangeIntersect => "*", + PgExpressionType.RangeExcept => "-", - PostgresExpressionType.TextSearchMatch => "@@", - PostgresExpressionType.TextSearchAnd => "&&", - PostgresExpressionType.TextSearchOr => "||", + PgExpressionType.TextSearchMatch => "@@", + PgExpressionType.TextSearchAnd => "&&", + PgExpressionType.TextSearchOr => "||", - PostgresExpressionType.JsonExists => "?", - PostgresExpressionType.JsonExistsAny => "?|", - PostgresExpressionType.JsonExistsAll => "?&", + PgExpressionType.JsonExists => "?", + PgExpressionType.JsonExistsAny => "?|", + PgExpressionType.JsonExistsAll => "?&", - PostgresExpressionType.LTreeMatches + PgExpressionType.LTreeMatches when binaryExpression.Right.TypeMapping.StoreType == "lquery" || binaryExpression.Right.TypeMapping is NpgsqlArrayTypeMapping { ElementTypeMapping.StoreType: "lquery" } => "~", - PostgresExpressionType.LTreeMatches + PgExpressionType.LTreeMatches when binaryExpression.Right.TypeMapping.StoreType == "ltxtquery" => "@", - PostgresExpressionType.LTreeMatchesAny => "?", - PostgresExpressionType.LTreeFirstAncestor => "?@>", - PostgresExpressionType.LTreeFirstDescendent => "?<@", - PostgresExpressionType.LTreeFirstMatches + PgExpressionType.LTreeMatchesAny => "?", + PgExpressionType.LTreeFirstAncestor => "?@>", + PgExpressionType.LTreeFirstDescendent => "?<@", + PgExpressionType.LTreeFirstMatches when binaryExpression.Right.TypeMapping.StoreType == "lquery" => "?~", - PostgresExpressionType.LTreeFirstMatches + PgExpressionType.LTreeFirstMatches when binaryExpression.Right.TypeMapping.StoreType == "ltxtquery" => "?@", - PostgresExpressionType.Distance => "<->", + PgExpressionType.Distance => "<->", _ => throw new ArgumentOutOfRangeException($"Unhandled operator type: {binaryExpression.OperatorType}") }) @@ -777,7 +777,7 @@ protected override void GenerateValues(ValuesExpression valuesExpression) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual Expression VisitArrayAll(PostgresAllExpression expression) + public virtual Expression VisitArrayAll(PgAllExpression expression) { Visit(expression.Item); @@ -785,8 +785,8 @@ public virtual Expression VisitArrayAll(PostgresAllExpression expression) .Append(" ") .Append(expression.OperatorType switch { - PostgresAllOperatorType.Like => "LIKE", - PostgresAllOperatorType.ILike => "ILIKE", + PgAllOperatorType.Like => "LIKE", + PgAllOperatorType.ILike => "ILIKE", _ => throw new ArgumentOutOfRangeException($"Unhandled operator type: {expression.OperatorType}") }) .Append(" ALL ("); @@ -804,7 +804,7 @@ public virtual Expression VisitArrayAll(PostgresAllExpression expression) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual Expression VisitArrayAny(PostgresAnyExpression expression) + public virtual Expression VisitArrayAny(PgAnyExpression expression) { Visit(expression.Item); @@ -812,9 +812,9 @@ public virtual Expression VisitArrayAny(PostgresAnyExpression expression) .Append(" ") .Append(expression.OperatorType switch { - PostgresAnyOperatorType.Equal => "=", - PostgresAnyOperatorType.Like => "LIKE", - PostgresAnyOperatorType.ILike => "ILIKE", + PgAnyOperatorType.Equal => "=", + PgAnyOperatorType.Like => "LIKE", + PgAnyOperatorType.ILike => "ILIKE", _ => throw new ArgumentOutOfRangeException($"Unhandled operator type: {expression.OperatorType}") }) .Append(" ANY ("); @@ -829,7 +829,7 @@ public virtual Expression VisitArrayAny(PostgresAnyExpression expression) /// /// Produces SQL array index expression (e.g. arr[1]). /// - public virtual Expression VisitArrayIndex(PostgresArrayIndexExpression expression) + public virtual Expression VisitArrayIndex(PgArrayIndexExpression expression) { Visit(expression.Array); Sql.Append("["); @@ -841,7 +841,7 @@ public virtual Expression VisitArrayIndex(PostgresArrayIndexExpression expressio /// /// Produces SQL array slice expression (e.g. arr[1:2]). /// - public virtual Expression VisitArraySlice(PostgresArraySliceExpression expression) + public virtual Expression VisitArraySlice(PgArraySliceExpression expression) { Visit(expression.Array); Sql.Append("["); @@ -853,7 +853,7 @@ public virtual Expression VisitArraySlice(PostgresArraySliceExpression expressio } /// - /// Visits the children of a . + /// Visits the children of a . /// /// The expression. /// @@ -862,7 +862,7 @@ public virtual Expression VisitArraySlice(PostgresArraySliceExpression expressio /// /// See: http://www.postgresql.org/docs/current/static/functions-matching.html /// - public virtual Expression VisitRegexMatch(PostgresRegexMatchExpression expression) + public virtual Expression VisitRegexMatch(PgRegexMatchExpression expression) { var options = expression.Options; @@ -936,7 +936,7 @@ public virtual Expression VisitRegexMatch(PostgresRegexMatchExpression expressio /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual Expression VisitRowValue(PostgresRowValueExpression rowValueExpression) + public virtual Expression VisitRowValue(PgRowValueExpression rowValueExpression) { Sql.Append("("); @@ -958,13 +958,13 @@ public virtual Expression VisitRowValue(PostgresRowValueExpression rowValueExpre } /// - /// Visits the children of an . + /// Visits the children of an . /// /// The expression. /// /// An . /// - public virtual Expression VisitILike(PostgresILikeExpression likeExpression) + public virtual Expression VisitILike(PgILikeExpression likeExpression) { Visit(likeExpression.Match); Sql.Append(" ILIKE "); @@ -980,13 +980,13 @@ public virtual Expression VisitILike(PostgresILikeExpression likeExpression) } /// - /// Visits the children of an . + /// Visits the children of an . /// /// The expression. /// /// An . /// - public virtual Expression VisitJsonPathTraversal(PostgresJsonTraversalExpression expression) + public virtual Expression VisitJsonPathTraversal(PgJsonTraversalExpression expression) { Visit(expression.Expression); @@ -1031,7 +1031,7 @@ public virtual Expression VisitJsonPathTraversal(PostgresJsonTraversalExpression /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual Expression VisitUnnestExpression(PostgresUnnestExpression unnestExpression) + protected virtual Expression VisitUnnestExpression(PgUnnestExpression unnestExpression) { // unnest docs: https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE @@ -1060,13 +1060,13 @@ protected virtual Expression VisitUnnestExpression(PostgresUnnestExpression unne } /// - /// Visits the children of a . + /// Visits the children of a . /// /// The expression. /// /// An . /// - public virtual Expression VisitUnknownBinary(PostgresUnknownBinaryExpression unknownBinaryExpression) + public virtual Expression VisitUnknownBinary(PgUnknownBinaryExpression unknownBinaryExpression) { Check.NotNull(unknownBinaryExpression, nameof(unknownBinaryExpression)); @@ -1108,13 +1108,13 @@ public virtual Expression VisitUnknownBinary(PostgresUnknownBinaryExpression unk /// - /// Visits the children of a . + /// Visits the children of a . /// /// The expression. /// /// An . /// - public virtual Expression VisitPostgresFunction(PostgresFunctionExpression e) + public virtual Expression VisitPostgresFunction(PgFunctionExpression e) { Check.NotNull(e, nameof(e)); @@ -1210,7 +1210,7 @@ protected override bool RequiresParentheses(SqlExpression outerExpression, SqlEx return true; // Copy paste of QuerySqlGenerator.RequiresParentheses for SqlBinaryExpression - case PostgresBinaryExpression innerBinary: + case PgBinaryExpression innerBinary: { // If the provider defined precedence for the two expression, use that if (TryGetOperatorInfo(outerExpression, out var outerPrecedence, out var isOuterAssociative) @@ -1223,7 +1223,7 @@ protected override bool RequiresParentheses(SqlExpression outerExpression, SqlEx // If both operators have the same precedence, add parentheses unless they're the same operator, and // that operator is associative (e.g. a + b + c) - 0 => outerExpression is not PostgresBinaryExpression outerBinary + 0 => outerExpression is not PgBinaryExpression outerBinary || outerBinary.OperatorType != innerBinary.OperatorType || !isOuterAssociative // Arithmetic operators on floating points aren't associative, because of rounding errors. @@ -1304,15 +1304,15 @@ protected override bool TryGetOperatorInfo(SqlExpression expression, out int pre // There's an "any other operator" category in the PG operator precedence table, we assign that a numeric value of 1000. // TODO: Some operators here may be associative - PostgresBinaryExpression => (1000, false), + PgBinaryExpression => (1000, false), CollateExpression => (1000, false), AtTimeZoneExpression => (1000, false), InExpression => (900, false), - PostgresJsonTraversalExpression => (1000, false), - PostgresArrayIndexExpression => (1500, false), - PostgresAllExpression or PostgresAnyExpression => (800, false), - LikeExpression or PostgresILikeExpression or PostgresRegexMatchExpression => (900, false), + PgJsonTraversalExpression => (1000, false), + PgArrayIndexExpression => (1500, false), + PgAllExpression or PgAnyExpression => (800, false), + LikeExpression or PgILikeExpression or PgRegexMatchExpression => (900, false), _ => default, }; diff --git a/src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.cs index 667447450..d52eccfff 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.cs @@ -123,7 +123,7 @@ protected override ShapedQueryExpression TranslatePrimitiveCollection( // to add ordering like in most other providers (https://www.postgresql.org/docs/current/functions-array.html) // We also don't need to apply any casts or typing, since PG arrays are fully typed (unlike e.g. a JSON string). selectExpression = new SelectExpression( - new PostgresUnnestExpression(tableAlias, sqlExpression, "value"), + new PgUnnestExpression(tableAlias, sqlExpression, "value"), columnName: "value", columnType: elementClrType, columnTypeMapping: elementTypeMapping, @@ -171,7 +171,7 @@ protected override Expression ApplyInferredTypeMappings( { if (source.QueryExpression is SelectExpression { - Tables: [(PostgresUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], + Tables: [(PgUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], Predicate: null, GroupBy: [], Having: null, @@ -195,12 +195,12 @@ protected override Expression ApplyInferredTypeMappings( { return BuildSimplifiedShapedQuery( source, - _sqlExpressionFactory.All(match, GetArray(sourceTable), PostgresAllOperatorType.Like)); + _sqlExpressionFactory.All(match, GetArray(sourceTable), PgAllOperatorType.Like)); } // Pattern match for: new[] { "a", "b", "c" }.All(p => EF.Functions.Like(e.SomeText, p)), // which we translate to WHERE s.""SomeText"" LIKE ALL (ARRAY['a','b','c']) - case PostgresILikeExpression + case PgILikeExpression { Match: var match, Pattern: ColumnExpression pattern, @@ -210,12 +210,12 @@ protected override Expression ApplyInferredTypeMappings( { return BuildSimplifiedShapedQuery( source, - _sqlExpressionFactory.All(match, GetArray(sourceTable), PostgresAllOperatorType.ILike)); + _sqlExpressionFactory.All(match, GetArray(sourceTable), PgAllOperatorType.ILike)); } // Pattern match for: e.SomeArray.All(p => ints.Contains(p)) over non-column, // using array containment (<@) - case PostgresAnyExpression + case PgAnyExpression { Item: ColumnExpression sourceColumn, Array: var otherArray @@ -227,11 +227,11 @@ protected override Expression ApplyInferredTypeMappings( // Pattern match for: new[] { 4, 5 }.All(p => e.SomeArray.Contains(p)) over column, // using array containment (<@) - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: PostgresExpressionType.Contains, + OperatorType: PgExpressionType.Contains, Left: var otherArray, - Right: PostgresNewArrayExpression { Expressions: [ColumnExpression sourceColumn] } + Right: PgNewArrayExpression { Expressions: [ColumnExpression sourceColumn] } } when sourceColumn.Table == sourceTable: { @@ -253,7 +253,7 @@ protected override Expression ApplyInferredTypeMappings( { if (source.QueryExpression is SelectExpression { - Tables: [(PostgresUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], + Tables: [(PgUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], Predicate: null, GroupBy: [], Having: null, @@ -296,12 +296,12 @@ protected override Expression ApplyInferredTypeMappings( when pattern.Table == sourceTable: { return BuildSimplifiedShapedQuery( - source, _sqlExpressionFactory.Any(match, GetArray(sourceTable), PostgresAnyOperatorType.Like)); + source, _sqlExpressionFactory.Any(match, GetArray(sourceTable), PgAnyOperatorType.Like)); } // Pattern match: new[] { "a", "b", "c" }.Any(p => EF.Functions.Like(e.SomeText, p)) // Translation: s.SomeText LIKE ANY (ARRAY['a','b','c']) - case PostgresILikeExpression + case PgILikeExpression { Match: var match, Pattern: ColumnExpression pattern, @@ -310,13 +310,13 @@ protected override Expression ApplyInferredTypeMappings( when pattern.Table == sourceTable: { return BuildSimplifiedShapedQuery( - source, _sqlExpressionFactory.Any(match, GetArray(sourceTable), PostgresAnyOperatorType.ILike)); + source, _sqlExpressionFactory.Any(match, GetArray(sourceTable), PgAnyOperatorType.ILike)); } // Array overlap over non-column // Pattern match: e.SomeArray.Any(p => ints.Contains(p)) // Translation: @ints && s.SomeArray - case PostgresAnyExpression + case PgAnyExpression { Item: ColumnExpression sourceColumn, Array: var otherArray @@ -329,11 +329,11 @@ protected override Expression ApplyInferredTypeMappings( // Array overlap over column // Pattern match: new[] { 4, 5 }.Any(p => e.SomeArray.Contains(p)) // Translation: s.SomeArray && ARRAY[4, 5] - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: PostgresExpressionType.Contains, + OperatorType: PgExpressionType.Contains, Left: var otherArray, - Right: PostgresNewArrayExpression { Expressions: [ColumnExpression sourceColumn] } + Right: PgNewArrayExpression { Expressions: [ColumnExpression sourceColumn] } } when sourceColumn.Table == sourceTable: { @@ -344,9 +344,9 @@ protected override Expression ApplyInferredTypeMappings( // Pattern match: new[] { "q1", "q2" }.Any(q => e.SomeLTree.MatchesLQuery(q)) // Translation: s.SomeLTree ? ARRAY['q1','q2'] - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: PostgresExpressionType.LTreeMatches, + OperatorType: PgExpressionType.LTreeMatches, Left: var ltree, Right: SqlUnaryExpression { OperatorType: ExpressionType.Convert, Operand: ColumnExpression lqueryColumn } } @@ -354,8 +354,8 @@ protected override Expression ApplyInferredTypeMappings( { return BuildSimplifiedShapedQuery( source, - new PostgresBinaryExpression( - PostgresExpressionType.LTreeMatchesAny, + new PgBinaryExpression( + PgExpressionType.LTreeMatchesAny, ltree, _sqlExpressionFactory.ApplyTypeMapping(GetArray(sourceTable), _typeMappingSource.FindMapping("lquery[]")), typeof(bool), @@ -366,9 +366,9 @@ protected override Expression ApplyInferredTypeMappings( // Translation: ARRAY['t1','t2'] @> s.SomeLTree // Pattern match: new[] { "t1", "t2" }.Any(t => t.IsDescendantOf(e.SomeLTree)) // Translation: ARRAY['t1','t2'] <@ s.SomeLTree - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: (PostgresExpressionType.Contains or PostgresExpressionType.ContainedBy) and var operatorType, + OperatorType: (PgExpressionType.Contains or PgExpressionType.ContainedBy) and var operatorType, Left: ColumnExpression ltreeColumn, // Contains/ContainedBy can happen for non-LTree types too, so check that Right: { TypeMapping: NpgsqlLTreeTypeMapping } ltree @@ -377,7 +377,7 @@ protected override Expression ApplyInferredTypeMappings( { return BuildSimplifiedShapedQuery( source, - new PostgresBinaryExpression( + new PgBinaryExpression( operatorType, _sqlExpressionFactory.ApplyDefaultTypeMapping(GetArray(sourceTable)), ltree, @@ -389,9 +389,9 @@ protected override Expression ApplyInferredTypeMappings( // Translation: ARRAY['t1','t2'] ~ lquery // Pattern match: new[] { "t1", "t2" }.Any(t => t.MatchesLTxtQuery(ltxtquery)) // Translation: ARRAY['t1','t2'] @ ltxtquery - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: PostgresExpressionType.LTreeMatches, + OperatorType: PgExpressionType.LTreeMatches, Left: ColumnExpression ltreeColumn, Right: var lquery } @@ -399,8 +399,8 @@ protected override Expression ApplyInferredTypeMappings( { return BuildSimplifiedShapedQuery( source, - new PostgresBinaryExpression( - PostgresExpressionType.LTreeMatches, + new PgBinaryExpression( + PgExpressionType.LTreeMatches, _sqlExpressionFactory.ApplyDefaultTypeMapping(GetArray(sourceTable)), lquery, typeof(bool), @@ -410,9 +410,9 @@ protected override Expression ApplyInferredTypeMappings( // Any within Any (i.e. intersection) // Pattern match: ltrees.Any(t => lqueries.Any(q => t.MatchesLQuery(q))) // Translate: ltrees ? lqueries - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: PostgresExpressionType.LTreeMatchesAny, + OperatorType: PgExpressionType.LTreeMatchesAny, Left: ColumnExpression ltreeColumn, Right: var lqueries } @@ -420,8 +420,8 @@ protected override Expression ApplyInferredTypeMappings( { return BuildSimplifiedShapedQuery( source, - new PostgresBinaryExpression( - PostgresExpressionType.LTreeMatchesAny, + new PgBinaryExpression( + PgExpressionType.LTreeMatchesAny, _sqlExpressionFactory.ApplyDefaultTypeMapping(GetArray(sourceTable)), lqueries, typeof(bool), @@ -441,7 +441,7 @@ protected override Expression ApplyInferredTypeMappings( { Source1: { - Tables: [PostgresUnnestExpression { Array: var array1 }], + Tables: [PgUnnestExpression { Array: var array1 }], GroupBy: [], Having: null, IsDistinct: false, @@ -450,7 +450,7 @@ protected override Expression ApplyInferredTypeMappings( }, Source2: { - Tables: [PostgresUnnestExpression { Array: var array2 }], + Tables: [PgUnnestExpression { Array: var array2 }], GroupBy: [], Having: null, IsDistinct: false, @@ -481,7 +481,7 @@ protected override Expression ApplyInferredTypeMappings( { if (source.QueryExpression is SelectExpression { - Tables: [(PostgresUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], + Tables: [(PgUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], Predicate: null, GroupBy: [], Having: null, @@ -531,7 +531,7 @@ protected override Expression ApplyInferredTypeMappings( // For constant arrays (new[] { 1, 2, 3 }) or inline arrays (new[] { 1, param, 3 }), don't do anything PG-specific for since // the general EF Core mechanism is fine for that case: item IN (1, 2, 3). - case SqlConstantExpression or PostgresNewArrayExpression: + case SqlConstantExpression or PgNewArrayExpression: break; // Similar to ParameterExpression below, but when a bare subquery is present inside ANY(), PostgreSQL just compares @@ -544,7 +544,7 @@ protected override Expression ApplyInferredTypeMappings( translatedItem, _sqlExpressionFactory.Convert( subqueryExpression, subqueryExpression.Type, subqueryExpression.TypeMapping), - PostgresAnyOperatorType.Equal)); + PgAnyOperatorType.Equal)); // For ParameterExpression, and for all other cases - e.g. array returned from some function - // translate to e.SomeText = ANY (@p). This is superior to the general solution which will expand @@ -552,7 +552,7 @@ protected override Expression ApplyInferredTypeMappings( // Note that this will allow indexes on the item to be used. default: return BuildSimplifiedShapedQuery( - source, _sqlExpressionFactory.Any(translatedItem, array, PostgresAnyOperatorType.Equal)); + source, _sqlExpressionFactory.Any(translatedItem, array, PgAnyOperatorType.Equal)); } } @@ -570,7 +570,7 @@ protected override Expression ApplyInferredTypeMappings( // Simplify x.Array.Count() => cardinality(x.Array) instead of SELECT COUNT(*) FROM unnest(x.Array) if (predicate is null && source.QueryExpression is SelectExpression { - Tables: [PostgresUnnestExpression { Array: var array }], + Tables: [PgUnnestExpression { Array: var array }], GroupBy: [], Having: null, IsDistinct: false, @@ -607,7 +607,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s // SELECT u.value FROM unnest(x.Array) UNION ALL SELECT u.value FROM unnest(y.Array) if (source1.QueryExpression is SelectExpression { - Tables: [PostgresUnnestExpression { Array: var array1 } unnestExpression1], + Tables: [PgUnnestExpression { Array: var array1 } unnestExpression1], GroupBy: [], Having: null, IsDistinct: false, @@ -617,7 +617,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s } && source2.QueryExpression is SelectExpression { - Tables: [PostgresUnnestExpression { Array: var array2 }], + Tables: [PgUnnestExpression { Array: var array2 }], GroupBy: [], Having: null, IsDistinct: false, @@ -637,7 +637,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s #pragma warning disable EF1001 // Internal EF Core API usage. var selectExpression = new SelectExpression( - new PostgresUnnestExpression(unnestExpression1.Alias, _sqlExpressionFactory.Add(array1, array2), "value"), + new PgUnnestExpression(unnestExpression1.Alias, _sqlExpressionFactory.Add(array1, array2), "value"), columnName: "value", columnType: projectedColumn1.Type, columnTypeMapping: inferredTypeMapping, @@ -681,7 +681,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s // Note that we have unnest over multiranges, not just arrays - but multiranges don't support subscripting/slicing. if (!returnDefault && source.QueryExpression is SelectExpression { - Tables: [PostgresUnnestExpression { Array: var array }], + Tables: [PgUnnestExpression { Array: var array }], GroupBy: [], Having: null, IsDistinct: false, @@ -721,7 +721,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s // select expression should already contain our predicate. if (source.QueryExpression is SelectExpression { - Tables: [(PostgresUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], + Tables: [(PgUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }) and var sourceTable], Predicate: var translatedPredicate, GroupBy: [], Having: null, @@ -747,9 +747,9 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s // Translation: ARRAY['t1','t2'] ?@> e.SomeLTree // Pattern match: new[] { "t1", "t2" }.FirstOrDefault(t => t.IsDescendant(e.SomeLTree)) // Translation: ARRAY['t1','t2'] ?<@ e.SomeLTree - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: (PostgresExpressionType.Contains or PostgresExpressionType.ContainedBy) and var operatorType, + OperatorType: (PgExpressionType.Contains or PgExpressionType.ContainedBy) and var operatorType, Left: ColumnExpression ltreeColumn, // Contains/ContainedBy can happen for non-LTree types too, so check that Right: { TypeMapping: NpgsqlLTreeTypeMapping } ltree @@ -758,10 +758,10 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s { return BuildSimplifiedShapedQuery( source, - new PostgresBinaryExpression( - operatorType == PostgresExpressionType.Contains - ? PostgresExpressionType.LTreeFirstAncestor - : PostgresExpressionType.LTreeFirstDescendent, + new PgBinaryExpression( + operatorType == PgExpressionType.Contains + ? PgExpressionType.LTreeFirstAncestor + : PgExpressionType.LTreeFirstDescendent, _sqlExpressionFactory.ApplyDefaultTypeMapping(GetArray(sourceTable)), ltree, typeof(LTree), @@ -772,9 +772,9 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s // Translation: ARRAY['t1','t2'] ?~ e.lquery // Pattern match: new[] { "t1", "t2" }.FirstOrDefault(t => t.MatchesLQuery(ltxtquery)) // Translation: ARRAY['t1','t2'] ?@ e.ltxtquery - case PostgresBinaryExpression + case PgBinaryExpression { - OperatorType: PostgresExpressionType.LTreeMatches, + OperatorType: PgExpressionType.LTreeMatches, Left: ColumnExpression ltreeColumn, Right: var lquery } @@ -782,8 +782,8 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s { return BuildSimplifiedShapedQuery( source, - new PostgresBinaryExpression( - PostgresExpressionType.LTreeFirstMatches, + new PgBinaryExpression( + PgExpressionType.LTreeFirstMatches, _sqlExpressionFactory.ApplyDefaultTypeMapping(GetArray(sourceTable)), lquery, typeof(LTree), @@ -807,7 +807,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s // Note that we have unnest over multiranges, not just arrays - but multiranges don't support subscripting/slicing. if (source.QueryExpression is SelectExpression { - Tables: [PostgresUnnestExpression { Array: var array } unnestExpression], + Tables: [PgUnnestExpression { Array: var array } unnestExpression], GroupBy: [], Having: null, IsDistinct: false, @@ -821,7 +821,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s { #pragma warning disable EF1001 // Internal EF Core API usage. var selectExpression = new SelectExpression( - new PostgresUnnestExpression( + new PgUnnestExpression( unnestExpression.Alias, _sqlExpressionFactory.ArraySlice( array, @@ -870,7 +870,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s // Note that we have unnest over multiranges, not just arrays - but multiranges don't support subscripting/slicing. if (source.QueryExpression is SelectExpression { - Tables: [PostgresUnnestExpression { Array: var array } unnestExpression], + Tables: [PgUnnestExpression { Array: var array } unnestExpression], GroupBy: [], Having: null, IsDistinct: false, @@ -887,12 +887,12 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s return base.TranslateTake(source, count); } - PostgresArraySliceExpression sliceExpression; + PgArraySliceExpression sliceExpression; // If Skip has been called before, an array slice expression is already there; try to integrate this Take into it. // Note that we need to take the Skip (lower bound) into account for the Take (upper bound), since the slice upper bound // operates on the original array (Skip hasn't yet taken place). - if (array is PostgresArraySliceExpression existingSliceExpression) + if (array is PgArraySliceExpression existingSliceExpression) { if (existingSliceExpression is { @@ -927,7 +927,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s #pragma warning disable EF1001 // Internal EF Core API usage. var selectExpression = new SelectExpression( - new PostgresUnnestExpression(unnestExpression.Alias, sliceExpression, "value"), + new PgUnnestExpression(unnestExpression.Alias, sliceExpression, "value"), "value", projectedColumn.Type, projectedColumn.TypeMapping, @@ -1064,7 +1064,7 @@ protected override bool IsValidSelectExpressionForExecuteDelete( // https://www.postgresql.org/docs/current/functions-array.html. /// protected override bool IsOrdered(SelectExpression selectExpression) - => base.IsOrdered(selectExpression) || selectExpression.Tables is [PostgresUnnestExpression]; + => base.IsOrdered(selectExpression) || selectExpression.Tables is [PgUnnestExpression]; /// /// Checks whether the given expression maps to a PostgreSQL array, as opposed to a multirange type. @@ -1117,18 +1117,18 @@ private ShapedQueryExpression BuildSimplifiedShapedQuery(ShapedQueryExpression s new ProjectionBindingExpression(translation, new ProjectionMember(), typeof(bool?)), typeof(bool))); /// - /// Extracts the out of . - /// If a is given, converts its literal values into a . + /// Extracts the out of . + /// If a is given, converts its literal values into a . /// private SqlExpression GetArray(TableExpressionBase tableExpression) { Check.DebugAssert( - tableExpression is PostgresUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }, + tableExpression is PgUnnestExpression or ValuesExpression { ColumnNames: ["_ord", "Value"] }, "Bad tableExpression"); switch (tableExpression) { - case PostgresUnnestExpression unnest: + case PgUnnestExpression unnest: return unnest.Array; case ValuesExpression valuesExpression: @@ -1143,7 +1143,7 @@ private SqlExpression GetArray(TableExpressionBase tableExpression) elements[i] = valuesExpression.RowValues[i].Values[1]; } - return new PostgresNewArrayExpression( + return new PgNewArrayExpression( elements, valuesExpression.RowValues[0].Values[1].Type.MakeArrayType(), typeMapping: null); } @@ -1227,7 +1227,7 @@ protected override Expression VisitExtension(Expression expression) { switch (expression) { - case PostgresUnnestExpression unnestExpression + case PgUnnestExpression unnestExpression when TryGetInferredTypeMapping(unnestExpression, unnestExpression.ColumnName, out var elementTypeMapping): { var collectionTypeMapping = _typeMappingSource.FindMapping(unnestExpression.Array.Type, Model, elementTypeMapping); diff --git a/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs b/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs index bd29ac051..584c14c3a 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs @@ -31,8 +31,8 @@ protected override SqlExpression VisitSqlBinary( if (sqlBinaryExpression is not { OperatorType: ExpressionType.Equal or ExpressionType.NotEqual, - Left: PostgresRowValueExpression leftRowValue, - Right: PostgresRowValueExpression rightRowValue + Left: PgRowValueExpression leftRowValue, + Right: PgRowValueExpression rightRowValue }) { return base.VisitSqlBinary(sqlBinaryExpression, allowOptimizedExpansion, out nullable); @@ -126,10 +126,10 @@ protected override SqlExpression VisitSqlBinary( operatorType, visitedLeftValues is null ? leftRowValue - : new PostgresRowValueExpression(visitedLeftValues, leftRowValue.Type, leftRowValue.TypeMapping), + : new PgRowValueExpression(visitedLeftValues, leftRowValue.Type, leftRowValue.TypeMapping), visitedRightValues is null ? rightRowValue - : new PostgresRowValueExpression(visitedRightValues, leftRowValue.Type, leftRowValue.TypeMapping), + : new PgRowValueExpression(visitedRightValues, leftRowValue.Type, leftRowValue.TypeMapping), null)!; } @@ -149,8 +149,8 @@ visitedRightValues is null _ => _sqlExpressionFactory.AndAlso( _sqlExpressionFactory.MakeBinary( sqlBinaryExpression.OperatorType, - new PostgresRowValueExpression(visitedLeftValues, leftRowValue.Type, leftRowValue.TypeMapping), - new PostgresRowValueExpression(visitedRightValues, rightRowValue.Type, rightRowValue.TypeMapping), + new PgRowValueExpression(visitedLeftValues, leftRowValue.Type, leftRowValue.TypeMapping), + new PgRowValueExpression(visitedRightValues, rightRowValue.Type, rightRowValue.TypeMapping), null)!, expandedExpression) }; @@ -176,17 +176,17 @@ protected override SqlExpression VisitCustomSqlExpression( out bool nullable) => sqlExpression switch { - PostgresAnyExpression e => VisitAny(e, allowOptimizedExpansion, out nullable), - PostgresAllExpression e => VisitAll(e, allowOptimizedExpansion, out nullable), - PostgresArrayIndexExpression e => VisitArrayIndex(e, allowOptimizedExpansion, out nullable), - PostgresArraySliceExpression e => VisitArraySlice(e, allowOptimizedExpansion, out nullable), - PostgresBinaryExpression e => VisitPostgresBinary(e, allowOptimizedExpansion, out nullable), - PostgresILikeExpression e => VisitILike(e, allowOptimizedExpansion, out nullable), - PostgresJsonTraversalExpression e => VisitJsonTraversal(e, allowOptimizedExpansion, out nullable), - PostgresNewArrayExpression e => VisitNewArray(e, allowOptimizedExpansion, out nullable), - PostgresRegexMatchExpression e => VisitRegexMatch(e, allowOptimizedExpansion, out nullable), - PostgresRowValueExpression e => VisitRowValueExpression(e, allowOptimizedExpansion, out nullable), - PostgresUnknownBinaryExpression e => VisitUnknownBinary(e, allowOptimizedExpansion, out nullable), + PgAnyExpression e => VisitAny(e, allowOptimizedExpansion, out nullable), + PgAllExpression e => VisitAll(e, allowOptimizedExpansion, out nullable), + PgArrayIndexExpression e => VisitArrayIndex(e, allowOptimizedExpansion, out nullable), + PgArraySliceExpression e => VisitArraySlice(e, allowOptimizedExpansion, out nullable), + PgBinaryExpression e => VisitPostgresBinary(e, allowOptimizedExpansion, out nullable), + PgILikeExpression e => VisitILike(e, allowOptimizedExpansion, out nullable), + PgJsonTraversalExpression e => VisitJsonTraversal(e, allowOptimizedExpansion, out nullable), + PgNewArrayExpression e => VisitNewArray(e, allowOptimizedExpansion, out nullable), + PgRegexMatchExpression e => VisitRegexMatch(e, allowOptimizedExpansion, out nullable), + PgRowValueExpression e => VisitRowValueExpression(e, allowOptimizedExpansion, out nullable), + PgUnknownBinaryExpression e => VisitUnknownBinary(e, allowOptimizedExpansion, out nullable), // PostgresFunctionExpression is visited via the SqlFunctionExpression override below @@ -199,7 +199,7 @@ protected override SqlExpression VisitCustomSqlExpression( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual SqlExpression VisitAny(PostgresAnyExpression anyExpression, bool allowOptimizedExpansion, out bool nullable) + protected virtual SqlExpression VisitAny(PgAnyExpression anyExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(anyExpression, nameof(anyExpression)); @@ -216,7 +216,7 @@ protected virtual SqlExpression VisitAny(PostgresAnyExpression anyExpression, bo // We only do null compensation for item = ANY(array), not for any other operator. // Note that LIKE (without ANY) doesn't get null-compensated either, so we're consistent with that. - if (anyExpression.OperatorType != PostgresAnyOperatorType.Equal) + if (anyExpression.OperatorType != PgAnyOperatorType.Equal) { // If the array is a constant and it contains a null, or if the array isn't a constant, // we assume the entire expression can be null. @@ -272,7 +272,7 @@ protected virtual SqlExpression VisitAny(PostgresAnyExpression anyExpression, bo /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual SqlExpression VisitAll(PostgresAllExpression allExpression, bool allowOptimizedExpansion, out bool nullable) + protected virtual SqlExpression VisitAll(PgAllExpression allExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(allExpression, nameof(allExpression)); @@ -300,7 +300,7 @@ protected virtual SqlExpression VisitAll(PostgresAllExpression allExpression, bo /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual SqlExpression VisitArrayIndex( - PostgresArrayIndexExpression arrayIndexExpression, bool allowOptimizedExpansion, out bool nullable) + PgArrayIndexExpression arrayIndexExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(arrayIndexExpression, nameof(arrayIndexExpression)); @@ -319,7 +319,7 @@ protected virtual SqlExpression VisitArrayIndex( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual SqlExpression VisitArraySlice( - PostgresArraySliceExpression arraySliceExpression, bool allowOptimizedExpansion, out bool nullable) + PgArraySliceExpression arraySliceExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(arraySliceExpression, nameof(arraySliceExpression)); @@ -338,7 +338,7 @@ protected virtual SqlExpression VisitArraySlice( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual SqlExpression VisitPostgresBinary(PostgresBinaryExpression binaryExpression, bool allowOptimizedExpansion, out bool nullable) + protected virtual SqlExpression VisitPostgresBinary(PgBinaryExpression binaryExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(binaryExpression, nameof(binaryExpression)); @@ -352,9 +352,9 @@ protected virtual SqlExpression VisitPostgresBinary(PostgresBinaryExpression bin nullable = binaryExpression.OperatorType switch { // The following LTree search methods return null for "not found" - PostgresExpressionType.LTreeFirstAncestor => true, - PostgresExpressionType.LTreeFirstDescendent => true, - PostgresExpressionType.LTreeFirstMatches => true, + PgExpressionType.LTreeFirstAncestor => true, + PgExpressionType.LTreeFirstDescendent => true, + PgExpressionType.LTreeFirstMatches => true, _ => leftNullable || rightNullable }; @@ -383,7 +383,7 @@ protected override SqlExpression VisitSqlFunction( if (sqlFunctionExpression.IsBuiltIn && string.Equals(sqlFunctionExpression.Name, "SUM", StringComparison.OrdinalIgnoreCase) && visitedBase is SqlFunctionExpression { Name: "COALESCE", Arguments: { } } coalesceExpression - && coalesceExpression.Arguments[0] is PostgresFunctionExpression wrappedFunctionExpression) + && coalesceExpression.Arguments[0] is PgFunctionExpression wrappedFunctionExpression) { // The base logic assumes sum is operating over numbers, which breaks sum over PG interval. // Detect that case and remove the coalesce entirely (note that we don't need coalescing since sum function is in @@ -400,11 +400,11 @@ protected override SqlExpression VisitSqlFunction( return coalesceExpression.Update(coalesceExpression.Instance, visitedArguments); } - return visitedBase is PostgresFunctionExpression pgFunctionExpression + return visitedBase is PgFunctionExpression pgFunctionExpression ? VisitPostgresFunctionComponents(pgFunctionExpression) : visitedBase; - PostgresFunctionExpression VisitPostgresFunctionComponents(PostgresFunctionExpression pgFunctionExpression) + PgFunctionExpression VisitPostgresFunctionComponents(PgFunctionExpression pgFunctionExpression) { var aggregateChanged = false; @@ -447,7 +447,7 @@ PostgresFunctionExpression VisitPostgresFunctionComponents(PostgresFunctionExpre /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual SqlExpression VisitILike(PostgresILikeExpression iLikeExpression, bool allowOptimizedExpansion, out bool nullable) + protected virtual SqlExpression VisitILike(PgILikeExpression iLikeExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(iLikeExpression, nameof(iLikeExpression)); @@ -473,7 +473,7 @@ protected virtual SqlExpression VisitILike(PostgresILikeExpression iLikeExpressi /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual SqlExpression VisitNewArray( - PostgresNewArrayExpression newArrayExpression, bool allowOptimizedExpansion, out bool nullable) + PgNewArrayExpression newArrayExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(newArrayExpression, nameof(newArrayExpression)); @@ -500,7 +500,7 @@ protected virtual SqlExpression VisitNewArray( nullable = false; return newInitializers is null ? newArrayExpression - : new PostgresNewArrayExpression(newInitializers, newArrayExpression.Type, newArrayExpression.TypeMapping); + : new PgNewArrayExpression(newInitializers, newArrayExpression.Type, newArrayExpression.TypeMapping); } /// @@ -510,7 +510,7 @@ protected virtual SqlExpression VisitNewArray( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual SqlExpression VisitRegexMatch( - PostgresRegexMatchExpression regexMatchExpression, bool allowOptimizedExpansion, out bool nullable) + PgRegexMatchExpression regexMatchExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(regexMatchExpression, nameof(regexMatchExpression)); @@ -529,7 +529,7 @@ protected virtual SqlExpression VisitRegexMatch( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual SqlExpression VisitJsonTraversal( - PostgresJsonTraversalExpression jsonTraversalExpression, bool allowOptimizedExpansion, out bool nullable) + PgJsonTraversalExpression jsonTraversalExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(jsonTraversalExpression, nameof(jsonTraversalExpression)); @@ -569,7 +569,7 @@ protected virtual SqlExpression VisitJsonTraversal( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual SqlExpression VisitRowValueExpression( - PostgresRowValueExpression rowValueExpression, + PgRowValueExpression rowValueExpression, bool allowOptimizedExpansion, out bool nullable) { @@ -603,16 +603,16 @@ protected virtual SqlExpression VisitRowValueExpression( } /// - /// Visits a and computes its nullability. + /// Visits a and computes its nullability. /// /// /// - /// A expression to visit. + /// A expression to visit. /// A bool value indicating if optimized expansion which considers null value as false value is allowed. /// A bool value indicating whether the sql expression is nullable. /// An optimized sql expression. protected virtual SqlExpression VisitUnknownBinary( - PostgresUnknownBinaryExpression unknownBinaryExpression, bool allowOptimizedExpansion, out bool nullable) + PgUnknownBinaryExpression unknownBinaryExpression, bool allowOptimizedExpansion, out bool nullable) { Check.NotNull(unknownBinaryExpression, nameof(unknownBinaryExpression)); diff --git a/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs b/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs index 89844d86a..39cfdc732 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs @@ -186,7 +186,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) var subtraction = _sqlExpressionFactory.MakeBinary( ExpressionType.Subtract, sqlLeft!, sqlRight!, _typeMappingSource.FindMapping(typeof(int)))!; - return PostgresFunctionExpression.CreateWithNamedArguments( + return PgFunctionExpression.CreateWithNamedArguments( "make_interval", new[] { subtraction }, new[] { "days" }, @@ -265,7 +265,7 @@ protected override Expression VisitNew(NewExpression newExpression) if (newExpression.Type.IsAssignableTo(typeof(ITuple))) { return TryTranslateArguments(out var sqlArguments) - ? new PostgresRowValueExpression(sqlArguments, newExpression.Type) + ? new PgRowValueExpression(sqlArguments, newExpression.Type) : QueryCompilationContext.NotTranslatedExpression; } diff --git a/src/EFCore.PG/Query/Internal/NpgsqlUnnestPostprocessor.cs b/src/EFCore.PG/Query/Internal/NpgsqlUnnestPostprocessor.cs index fff8722c5..6297f3dda 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlUnnestPostprocessor.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlUnnestPostprocessor.cs @@ -7,7 +7,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal; /// -/// Locates instances of in the tree and prunes the WITH ORDINALITY clause from them if the +/// Locates instances of in the tree and prunes the WITH ORDINALITY clause from them if the /// ordinality column isn't referenced anywhere. /// /// @@ -42,7 +42,7 @@ public class NpgsqlUnnestPostprocessor : ExpressionVisitor // Find any unnest table which does not have any references to its ordinality column in the projection or orderings // (this is where they may appear when a column is an identifier). - var unnest = table as PostgresUnnestExpression ?? (table as JoinExpressionBase)?.Table as PostgresUnnestExpression; + var unnest = table as PgUnnestExpression ?? (table as JoinExpressionBase)?.Table as PgUnnestExpression; if (unnest is not null && !selectExpression.Orderings.Select(o => o.Expression) .Concat(selectExpression.Projection.Select(p => p.Expression)) @@ -59,7 +59,7 @@ public class NpgsqlUnnestPostprocessor : ExpressionVisitor } } - var newUnnest = new PostgresUnnestExpression(unnest.Alias, unnest.Array, unnest.ColumnName, withOrdinality: false); + var newUnnest = new PgUnnestExpression(unnest.Alias, unnest.Array, unnest.ColumnName, withOrdinality: false); // TODO: Simplify this via the newly-introduced JoinExpressionBase.Update newTables[i] = table switch @@ -69,7 +69,7 @@ public class NpgsqlUnnestPostprocessor : ExpressionVisitor CrossJoinExpression cj => cj.Update(newUnnest), CrossApplyExpression ca => ca.Update(newUnnest), OuterApplyExpression oa => oa.Update(newUnnest), - PostgresUnnestExpression => newUnnest, + PgUnnestExpression => newUnnest, _ => throw new UnreachableException() }; } diff --git a/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs b/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs index d84ee50ce..9e6930e1a 100644 --- a/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs +++ b/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs @@ -35,35 +35,35 @@ public NpgsqlSqlExpressionFactory(SqlExpressionFactoryDependencies dependencies) #region Expression factory methods /// - /// Creates a new , corresponding to the PostgreSQL-specific ~ operator. + /// Creates a new , corresponding to the PostgreSQL-specific ~ operator. /// - public virtual PostgresRegexMatchExpression RegexMatch( + public virtual PgRegexMatchExpression RegexMatch( SqlExpression match, SqlExpression pattern, RegexOptions options) - => (PostgresRegexMatchExpression)ApplyDefaultTypeMapping(new PostgresRegexMatchExpression(match, pattern, options, null)); + => (PgRegexMatchExpression)ApplyDefaultTypeMapping(new PgRegexMatchExpression(match, pattern, options, null)); /// - /// Creates a new , corresponding to the PostgreSQL-specific = ANY operator. + /// Creates a new , corresponding to the PostgreSQL-specific = ANY operator. /// - public virtual PostgresAnyExpression Any( + public virtual PgAnyExpression Any( SqlExpression item, SqlExpression array, - PostgresAnyOperatorType operatorType) - => (PostgresAnyExpression)ApplyDefaultTypeMapping(new PostgresAnyExpression(item, array, operatorType, null)); + PgAnyOperatorType operatorType) + => (PgAnyExpression)ApplyDefaultTypeMapping(new PgAnyExpression(item, array, operatorType, null)); /// - /// Creates a new , corresponding to the PostgreSQL-specific LIKE ALL operator. + /// Creates a new , corresponding to the PostgreSQL-specific LIKE ALL operator. /// - public virtual PostgresAllExpression All( + public virtual PgAllExpression All( SqlExpression item, SqlExpression array, - PostgresAllOperatorType operatorType) - => (PostgresAllExpression)ApplyDefaultTypeMapping(new PostgresAllExpression(item, array, operatorType, null)); + PgAllOperatorType operatorType) + => (PgAllExpression)ApplyDefaultTypeMapping(new PgAllExpression(item, array, operatorType, null)); /// - /// Creates a new , corresponding to the PostgreSQL-specific array subscripting operator. + /// Creates a new , corresponding to the PostgreSQL-specific array subscripting operator. /// - public virtual PostgresArrayIndexExpression ArrayIndex( + public virtual PgArrayIndexExpression ArrayIndex( SqlExpression array, SqlExpression index, bool nullable, @@ -74,22 +74,22 @@ public virtual PostgresArrayIndexExpression ArrayIndex( throw new ArgumentException("Array expression must be of an array or List<> type", nameof(array)); } - return (PostgresArrayIndexExpression)ApplyTypeMapping( - new PostgresArrayIndexExpression(array, index, nullable, elementType, typeMapping: null), + return (PgArrayIndexExpression)ApplyTypeMapping( + new PgArrayIndexExpression(array, index, nullable, elementType, typeMapping: null), typeMapping); } /// - /// Creates a new , corresponding to the PostgreSQL-specific array subscripting operator. + /// Creates a new , corresponding to the PostgreSQL-specific array subscripting operator. /// - public virtual PostgresArraySliceExpression ArraySlice( + public virtual PgArraySliceExpression ArraySlice( SqlExpression array, SqlExpression? lowerBound, SqlExpression? upperBound, bool nullable, RelationalTypeMapping? typeMapping = null) - => (PostgresArraySliceExpression)ApplyTypeMapping( - new PostgresArraySliceExpression(array, lowerBound, upperBound, nullable, array.Type, typeMapping: null), + => (PgArraySliceExpression)ApplyTypeMapping( + new PgArraySliceExpression(array, lowerBound, upperBound, nullable, array.Type, typeMapping: null), typeMapping); /// @@ -136,16 +136,16 @@ public virtual AtTimeZoneExpression AtTimeZone( /// Creates a new , for performing a PostgreSQL-specific case-insensitive string match /// (ILIKE). /// - public virtual PostgresILikeExpression ILike( + public virtual PgILikeExpression ILike( SqlExpression match, SqlExpression pattern, SqlExpression? escapeChar = null) - => (PostgresILikeExpression)ApplyDefaultTypeMapping(new PostgresILikeExpression(match, pattern, escapeChar, null)); + => (PgILikeExpression)ApplyDefaultTypeMapping(new PgILikeExpression(match, pattern, escapeChar, null)); /// - /// Creates a new , for traversing inside a JSON document. + /// Creates a new , for traversing inside a JSON document. /// - public virtual PostgresJsonTraversalExpression JsonTraversal( + public virtual PgJsonTraversalExpression JsonTraversal( SqlExpression expression, bool returnsText, Type type, @@ -153,9 +153,9 @@ public virtual PostgresJsonTraversalExpression JsonTraversal( => JsonTraversal(expression, Array.Empty(), returnsText, type, typeMapping); /// - /// Creates a new , for traversing inside a JSON document. + /// Creates a new , for traversing inside a JSON document. /// - public virtual PostgresJsonTraversalExpression JsonTraversal( + public virtual PgJsonTraversalExpression JsonTraversal( SqlExpression expression, IEnumerable path, bool returnsText, @@ -169,7 +169,7 @@ public virtual PostgresJsonTraversalExpression JsonTraversal( typeMapping); /// - /// Constructs either a , or, if all provided expressions are constants, a single + /// Constructs either a , or, if all provided expressions are constants, a single /// for the entire array. /// public virtual SqlExpression NewArrayOrConstant( @@ -217,13 +217,13 @@ public virtual SqlExpression NewArrayOrConstant( } /// - /// Creates a new , for creating a new PostgreSQL array. + /// Creates a new , for creating a new PostgreSQL array. /// - public virtual PostgresNewArrayExpression NewArray( + public virtual PgNewArrayExpression NewArray( IReadOnlyList expressions, Type type, RelationalTypeMapping? typeMapping = null) - => (PostgresNewArrayExpression)ApplyTypeMapping(new PostgresNewArrayExpression(expressions, type, typeMapping), typeMapping); + => (PgNewArrayExpression)ApplyTypeMapping(new PgNewArrayExpression(expressions, type, typeMapping), typeMapping); /// public override SqlBinaryExpression? MakeBinary( @@ -273,15 +273,15 @@ public virtual PostgresNewArrayExpression NewArray( } /// - /// Creates a new with the given arguments. + /// Creates a new with the given arguments. /// /// An representing SQL unary operator. /// The left operand of binary operation. /// The right operand of binary operation. /// A type mapping to be assigned to the created expression. - /// A with the given arguments. - public virtual PostgresBinaryExpression MakePostgresBinary( - PostgresExpressionType operatorType, + /// A with the given arguments. + public virtual PgBinaryExpression MakePostgresBinary( + PgExpressionType operatorType, SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) @@ -292,70 +292,70 @@ public virtual PostgresBinaryExpression MakePostgresBinary( var returnType = left.Type; switch (operatorType) { - case PostgresExpressionType.Contains: - case PostgresExpressionType.ContainedBy: - case PostgresExpressionType.Overlaps: - case PostgresExpressionType.NetworkContainedByOrEqual: - case PostgresExpressionType.NetworkContainsOrEqual: - case PostgresExpressionType.NetworkContainsOrContainedBy: - case PostgresExpressionType.RangeIsStrictlyLeftOf: - case PostgresExpressionType.RangeIsStrictlyRightOf: - case PostgresExpressionType.RangeDoesNotExtendRightOf: - case PostgresExpressionType.RangeDoesNotExtendLeftOf: - case PostgresExpressionType.RangeIsAdjacentTo: - case PostgresExpressionType.TextSearchMatch: - case PostgresExpressionType.JsonExists: - case PostgresExpressionType.JsonExistsAny: - case PostgresExpressionType.JsonExistsAll: + case PgExpressionType.Contains: + case PgExpressionType.ContainedBy: + case PgExpressionType.Overlaps: + case PgExpressionType.NetworkContainedByOrEqual: + case PgExpressionType.NetworkContainsOrEqual: + case PgExpressionType.NetworkContainsOrContainedBy: + case PgExpressionType.RangeIsStrictlyLeftOf: + case PgExpressionType.RangeIsStrictlyRightOf: + case PgExpressionType.RangeDoesNotExtendRightOf: + case PgExpressionType.RangeDoesNotExtendLeftOf: + case PgExpressionType.RangeIsAdjacentTo: + case PgExpressionType.TextSearchMatch: + case PgExpressionType.JsonExists: + case PgExpressionType.JsonExistsAny: + case PgExpressionType.JsonExistsAll: returnType = typeof(bool); break; - case PostgresExpressionType.Distance: + case PgExpressionType.Distance: returnType = typeof(double); break; } - return (PostgresBinaryExpression)ApplyTypeMapping( - new PostgresBinaryExpression(operatorType, left, right, returnType, null), typeMapping); + return (PgBinaryExpression)ApplyTypeMapping( + new PgBinaryExpression(operatorType, left, right, returnType, null), typeMapping); } /// - /// Creates a new , for checking whether one value contains another. + /// Creates a new , for checking whether one value contains another. /// - public virtual PostgresBinaryExpression Contains(SqlExpression left, SqlExpression right) + public virtual PgBinaryExpression Contains(SqlExpression left, SqlExpression right) { Check.NotNull(left, nameof(left)); Check.NotNull(right, nameof(right)); - return MakePostgresBinary(PostgresExpressionType.Contains, left, right); + return MakePostgresBinary(PgExpressionType.Contains, left, right); } /// - /// Creates a new , for checking whether one value is contained by another. + /// Creates a new , for checking whether one value is contained by another. /// - public virtual PostgresBinaryExpression ContainedBy(SqlExpression left, SqlExpression right) + public virtual PgBinaryExpression ContainedBy(SqlExpression left, SqlExpression right) { Check.NotNull(left, nameof(left)); Check.NotNull(right, nameof(right)); - return MakePostgresBinary(PostgresExpressionType.ContainedBy, left, right); + return MakePostgresBinary(PgExpressionType.ContainedBy, left, right); } /// - /// Creates a new , for checking whether one value overlaps with another. + /// Creates a new , for checking whether one value overlaps with another. /// - public virtual PostgresBinaryExpression Overlaps(SqlExpression left, SqlExpression right) + public virtual PgBinaryExpression Overlaps(SqlExpression left, SqlExpression right) { Check.NotNull(left, nameof(left)); Check.NotNull(right, nameof(right)); - return MakePostgresBinary(PostgresExpressionType.Overlaps, left, right); + return MakePostgresBinary(PgExpressionType.Overlaps, left, right); } /// - /// Creates a new for a PostgreSQL aggregate function call.. + /// Creates a new for a PostgreSQL aggregate function call.. /// - public virtual PostgresFunctionExpression AggregateFunction( + public virtual PgFunctionExpression AggregateFunction( string name, IEnumerable arguments, EnumerableExpression aggregateEnumerableExpression, @@ -371,7 +371,7 @@ public virtual PostgresFunctionExpression AggregateFunction( typeMappedArguments.Add(ApplyDefaultTypeMapping(argument)); } - return new PostgresFunctionExpression( + return new PgFunctionExpression( name, typeMappedArguments, argumentNames: null, @@ -396,16 +396,16 @@ public virtual PostgresFunctionExpression AggregateFunction( SqlBinaryExpression e => ApplyTypeMappingOnSqlBinary(e, typeMapping), // PostgreSQL-specific expression types - PostgresAnyExpression e => ApplyTypeMappingOnAny(e), - PostgresAllExpression e => ApplyTypeMappingOnAll(e), - PostgresArrayIndexExpression e => ApplyTypeMappingOnArrayIndex(e, typeMapping), - PostgresArraySliceExpression e => ApplyTypeMappingOnArraySlice(e, typeMapping), - PostgresBinaryExpression e => ApplyTypeMappingOnPostgresBinary(e, typeMapping), - PostgresFunctionExpression e => e.ApplyTypeMapping(typeMapping), - PostgresILikeExpression e => ApplyTypeMappingOnILike(e), - PostgresNewArrayExpression e => ApplyTypeMappingOnNewArray(e, typeMapping), - PostgresRegexMatchExpression e => ApplyTypeMappingOnRegexMatch(e), - PostgresRowValueExpression e => ApplyTypeMappingOnRowValue(e, typeMapping), + PgAnyExpression e => ApplyTypeMappingOnAny(e), + PgAllExpression e => ApplyTypeMappingOnAll(e), + PgArrayIndexExpression e => ApplyTypeMappingOnArrayIndex(e, typeMapping), + PgArraySliceExpression e => ApplyTypeMappingOnArraySlice(e, typeMapping), + PgBinaryExpression e => ApplyTypeMappingOnPostgresBinary(e, typeMapping), + PgFunctionExpression e => e.ApplyTypeMapping(typeMapping), + PgILikeExpression e => ApplyTypeMappingOnILike(e), + PgNewArrayExpression e => ApplyTypeMappingOnNewArray(e, typeMapping), + PgRegexMatchExpression e => ApplyTypeMappingOnRegexMatch(e), + PgRowValueExpression e => ApplyTypeMappingOnRowValue(e, typeMapping), _ => base.ApplyTypeMapping(sqlExpression, typeMapping) }; @@ -503,8 +503,8 @@ private SqlBinaryExpression ApplyTypeMappingOnSqlBinary(SqlBinaryExpression bina // SqlConstantExpression. This is because each value in the row value needs to have its type mapping. binary = new SqlBinaryExpression( binary.OperatorType, - new PostgresRowValueExpression(updatedLeftValues, binary.Left.Type), - new PostgresRowValueExpression(updatedRightValues, binary.Right.Type), + new PgRowValueExpression(updatedLeftValues, binary.Left.Type), + new PgRowValueExpression(updatedRightValues, binary.Right.Type), binary.Type, binary.TypeMapping); } @@ -531,7 +531,7 @@ bool TryGetRowValueValues(SqlExpression e, [NotNullWhen(true)] out IReadOnlyList { switch (e) { - case PostgresRowValueExpression rowValueExpression: + case PgRowValueExpression rowValueExpression: values = rowValueExpression.Values; return true; @@ -553,46 +553,46 @@ bool TryGetRowValueValues(SqlExpression e, [NotNullWhen(true)] out IReadOnlyList } } - private SqlExpression ApplyTypeMappingOnRegexMatch(PostgresRegexMatchExpression postgresRegexMatchExpression) + private SqlExpression ApplyTypeMappingOnRegexMatch(PgRegexMatchExpression pgRegexMatchExpression) { var inferredTypeMapping = ExpressionExtensions.InferTypeMapping( - postgresRegexMatchExpression.Match, postgresRegexMatchExpression.Pattern) - ?? _typeMappingSource.FindMapping(postgresRegexMatchExpression.Match.Type, Dependencies.Model); + pgRegexMatchExpression.Match, pgRegexMatchExpression.Pattern) + ?? _typeMappingSource.FindMapping(pgRegexMatchExpression.Match.Type, Dependencies.Model); - return new PostgresRegexMatchExpression( - ApplyTypeMapping(postgresRegexMatchExpression.Match, inferredTypeMapping), - ApplyTypeMapping(postgresRegexMatchExpression.Pattern, inferredTypeMapping), - postgresRegexMatchExpression.Options, + return new PgRegexMatchExpression( + ApplyTypeMapping(pgRegexMatchExpression.Match, inferredTypeMapping), + ApplyTypeMapping(pgRegexMatchExpression.Pattern, inferredTypeMapping), + pgRegexMatchExpression.Options, _boolTypeMapping); } private SqlExpression ApplyTypeMappingOnRowValue( - PostgresRowValueExpression postgresRowValueExpression, + PgRowValueExpression pgRowValueExpression, RelationalTypeMapping? typeMapping) { // If the row value is in a binary expression (e.g. a comparison, (a, b) > (5, 6)), we have special type inference code // to infer from the other row value in ApplyTypeMappingOnSqlBinary. // If we're here, that means that no such inference can happen, and we just use the default type mappings. - var updatedValues = new SqlExpression[postgresRowValueExpression.Values.Count]; + var updatedValues = new SqlExpression[pgRowValueExpression.Values.Count]; for (var i = 0; i < updatedValues.Length; i++) { - updatedValues[i] = ApplyDefaultTypeMapping(postgresRowValueExpression.Values[i]); + updatedValues[i] = ApplyDefaultTypeMapping(pgRowValueExpression.Values[i]); } - return new PostgresRowValueExpression(updatedValues, postgresRowValueExpression.Type, typeMapping); + return new PgRowValueExpression(updatedValues, pgRowValueExpression.Type, typeMapping); } - private SqlExpression ApplyTypeMappingOnAny(PostgresAnyExpression postgresAnyExpression) + private SqlExpression ApplyTypeMappingOnAny(PgAnyExpression pgAnyExpression) { - var (item, array) = ApplyTypeMappingsOnItemAndArray(postgresAnyExpression.Item, postgresAnyExpression.Array); - return new PostgresAnyExpression(item, array, postgresAnyExpression.OperatorType, _boolTypeMapping); + var (item, array) = ApplyTypeMappingsOnItemAndArray(pgAnyExpression.Item, pgAnyExpression.Array); + return new PgAnyExpression(item, array, pgAnyExpression.OperatorType, _boolTypeMapping); } - private SqlExpression ApplyTypeMappingOnAll(PostgresAllExpression postgresAllExpression) + private SqlExpression ApplyTypeMappingOnAll(PgAllExpression pgAllExpression) { - var (item, array) = ApplyTypeMappingsOnItemAndArray(postgresAllExpression.Item, postgresAllExpression.Array); - return new PostgresAllExpression(item, array, postgresAllExpression.OperatorType, _boolTypeMapping); + var (item, array) = ApplyTypeMappingsOnItemAndArray(pgAllExpression.Item, pgAllExpression.Array); + return new PgAllExpression(item, array, pgAllExpression.OperatorType, _boolTypeMapping); } internal (SqlExpression, SqlExpression) ApplyTypeMappingsOnItemAndArray(SqlExpression itemExpression, SqlExpression arrayExpression) @@ -645,29 +645,29 @@ private SqlExpression ApplyTypeMappingOnAll(PostgresAllExpression postgresAllExp } private SqlExpression ApplyTypeMappingOnArrayIndex( - PostgresArrayIndexExpression postgresArrayIndexExpression, + PgArrayIndexExpression pgArrayIndexExpression, RelationalTypeMapping? typeMapping) { // If a (non-null) type mapping is being applied, it's to the element being indexed. // Infer the array's mapping from that. var (_, array) = typeMapping is not null - ? ApplyTypeMappingsOnItemAndArray(Constant(null, typeMapping), postgresArrayIndexExpression.Array) - : (null, ApplyDefaultTypeMapping(postgresArrayIndexExpression.Array)); + ? ApplyTypeMappingsOnItemAndArray(Constant(null, typeMapping), pgArrayIndexExpression.Array) + : (null, ApplyDefaultTypeMapping(pgArrayIndexExpression.Array)); - return new PostgresArrayIndexExpression( + return new PgArrayIndexExpression( array, - ApplyDefaultTypeMapping(postgresArrayIndexExpression.Index), - postgresArrayIndexExpression.IsNullable, - postgresArrayIndexExpression.Type, + ApplyDefaultTypeMapping(pgArrayIndexExpression.Index), + pgArrayIndexExpression.IsNullable, + pgArrayIndexExpression.Type, // If the array has a type mapping (i.e. column), prefer that just like we prefer column mappings in general - postgresArrayIndexExpression.Array.TypeMapping is NpgsqlArrayTypeMapping arrayMapping + pgArrayIndexExpression.Array.TypeMapping is NpgsqlArrayTypeMapping arrayMapping ? arrayMapping.ElementTypeMapping : typeMapping - ?? _typeMappingSource.FindMapping(postgresArrayIndexExpression.Type, Dependencies.Model)); + ?? _typeMappingSource.FindMapping(pgArrayIndexExpression.Type, Dependencies.Model)); } private SqlExpression ApplyTypeMappingOnArraySlice( - PostgresArraySliceExpression slice, + PgArraySliceExpression slice, RelationalTypeMapping? typeMapping) { // If the slice operand has a type mapping, that bubbles up (slice is just a view over that). Otherwise apply the external type @@ -677,7 +677,7 @@ private SqlExpression ApplyTypeMappingOnArraySlice( // Infer the array's mapping from that. var array = ApplyTypeMapping(slice.Array, typeMapping); - return new PostgresArraySliceExpression( + return new PgArraySliceExpression( array, slice.LowerBound is null ? null : ApplyDefaultTypeMapping(slice.LowerBound), slice.UpperBound is null ? null : ApplyDefaultTypeMapping(slice.UpperBound), @@ -686,7 +686,7 @@ private SqlExpression ApplyTypeMappingOnArraySlice( array.TypeMapping); } - private SqlExpression ApplyTypeMappingOnILike(PostgresILikeExpression ilikeExpression) + private SqlExpression ApplyTypeMappingOnILike(PgILikeExpression ilikeExpression) { var inferredTypeMapping = (ilikeExpression.EscapeChar is null ? ExpressionExtensions.InferTypeMapping( @@ -696,7 +696,7 @@ private SqlExpression ApplyTypeMappingOnILike(PostgresILikeExpression ilikeExpre ilikeExpression.EscapeChar)) ?? _typeMappingSource.FindMapping(ilikeExpression.Match.Type, Dependencies.Model); - return new PostgresILikeExpression( + return new PgILikeExpression( ApplyTypeMapping(ilikeExpression.Match, inferredTypeMapping), ApplyTypeMapping(ilikeExpression.Pattern, inferredTypeMapping), ApplyTypeMapping(ilikeExpression.EscapeChar, inferredTypeMapping), @@ -704,24 +704,24 @@ private SqlExpression ApplyTypeMappingOnILike(PostgresILikeExpression ilikeExpre } private SqlExpression ApplyTypeMappingOnPostgresBinary( - PostgresBinaryExpression postgresBinaryExpression, RelationalTypeMapping? typeMapping) + PgBinaryExpression pgBinaryExpression, RelationalTypeMapping? typeMapping) { - var (left, right) = (postgresBinaryExpression.Left, postgresBinaryExpression.Right); + var (left, right) = (pgBinaryExpression.Left, pgBinaryExpression.Right); Type resultType; RelationalTypeMapping? resultTypeMapping = null; RelationalTypeMapping? inferredTypeMapping; - var operatorType = postgresBinaryExpression.OperatorType; + var operatorType = pgBinaryExpression.OperatorType; switch (operatorType) { - case PostgresExpressionType.Overlaps: - case PostgresExpressionType.Contains: - case PostgresExpressionType.ContainedBy: - case PostgresExpressionType.RangeIsStrictlyLeftOf: - case PostgresExpressionType.RangeIsStrictlyRightOf: - case PostgresExpressionType.RangeDoesNotExtendRightOf: - case PostgresExpressionType.RangeDoesNotExtendLeftOf: - case PostgresExpressionType.RangeIsAdjacentTo: + case PgExpressionType.Overlaps: + case PgExpressionType.Contains: + case PgExpressionType.ContainedBy: + case PgExpressionType.RangeIsStrictlyLeftOf: + case PgExpressionType.RangeIsStrictlyRightOf: + case PgExpressionType.RangeDoesNotExtendRightOf: + case PgExpressionType.RangeDoesNotExtendLeftOf: + case PgExpressionType.RangeIsAdjacentTo: { resultType = typeof(bool); resultTypeMapping = _boolTypeMapping; @@ -741,7 +741,7 @@ private SqlExpression ApplyTypeMappingOnPostgresBinary( // We need fancier type mapping inference. SqlExpression newLeft, newRight; - if (operatorType == PostgresExpressionType.ContainedBy) + if (operatorType == PgExpressionType.ContainedBy) { (newRight, newLeft) = InferContainmentMappings(right, left); } @@ -750,20 +750,20 @@ private SqlExpression ApplyTypeMappingOnPostgresBinary( (newLeft, newRight) = InferContainmentMappings(left, right); } - return new PostgresBinaryExpression(operatorType, newLeft, newRight, resultType, resultTypeMapping); + return new PgBinaryExpression(operatorType, newLeft, newRight, resultType, resultTypeMapping); } - case PostgresExpressionType.NetworkContainedByOrEqual: - case PostgresExpressionType.NetworkContainsOrEqual: - case PostgresExpressionType.NetworkContainsOrContainedBy: - case PostgresExpressionType.TextSearchMatch: - case PostgresExpressionType.JsonExists: - case PostgresExpressionType.JsonExistsAny: - case PostgresExpressionType.JsonExistsAll: + case PgExpressionType.NetworkContainedByOrEqual: + case PgExpressionType.NetworkContainsOrEqual: + case PgExpressionType.NetworkContainsOrContainedBy: + case PgExpressionType.TextSearchMatch: + case PgExpressionType.JsonExists: + case PgExpressionType.JsonExistsAny: + case PgExpressionType.JsonExistsAll: { // TODO: For networking, this probably needs to be cleaned up, i.e. we know where the CIDR and INET are // based on operator type? - return new PostgresBinaryExpression( + return new PgBinaryExpression( operatorType, ApplyDefaultTypeMapping(left), ApplyDefaultTypeMapping(right), @@ -771,11 +771,11 @@ private SqlExpression ApplyTypeMappingOnPostgresBinary( _boolTypeMapping); } - case PostgresExpressionType.RangeUnion: - case PostgresExpressionType.RangeIntersect: - case PostgresExpressionType.RangeExcept: - case PostgresExpressionType.TextSearchAnd: - case PostgresExpressionType.TextSearchOr: + case PgExpressionType.RangeUnion: + case PgExpressionType.RangeIntersect: + case PgExpressionType.RangeExcept: + case PgExpressionType.TextSearchAnd: + case PgExpressionType.TextSearchOr: { inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right); resultType = inferredTypeMapping?.ClrType ?? left.Type; @@ -783,7 +783,7 @@ private SqlExpression ApplyTypeMappingOnPostgresBinary( break; } - case PostgresExpressionType.Distance: + case PgExpressionType.Distance: { inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right); @@ -812,10 +812,10 @@ when left.Type.FullName is "NodaTime.Instant" or "NodaTime.LocalDateTime" or "No default: throw new InvalidOperationException( - $"Incorrect {nameof(operatorType)} for {nameof(postgresBinaryExpression)}: {operatorType}"); + $"Incorrect {nameof(operatorType)} for {nameof(pgBinaryExpression)}: {operatorType}"); } - return new PostgresBinaryExpression( + return new PgBinaryExpression( operatorType, ApplyTypeMapping(left, inferredTypeMapping), ApplyTypeMapping(right, inferredTypeMapping), @@ -894,7 +894,7 @@ NpgsqlMultirangeTypeMapping multirangeTypeMapping } private SqlExpression ApplyTypeMappingOnNewArray( - PostgresNewArrayExpression postgresNewArrayExpression, RelationalTypeMapping? typeMapping) + PgNewArrayExpression pgNewArrayExpression, RelationalTypeMapping? typeMapping) { var arrayTypeMapping = typeMapping as NpgsqlArrayTypeMapping; if (arrayTypeMapping is null && typeMapping is not null) @@ -906,7 +906,7 @@ private SqlExpression ApplyTypeMappingOnNewArray( // First, loop over the expressions to infer the array's type mapping (if not provided), and to make // sure we don't have heterogeneous store types. - foreach (var expression in postgresNewArrayExpression.Expressions) + foreach (var expression in pgNewArrayExpression.Expressions) { if (expression.TypeMapping is not { } expressionTypeMapping) { @@ -978,7 +978,7 @@ static bool IsTextualTypeMapping(RelationalTypeMapping mapping) // we have no type mapping... Just return the original expression, which has no type mapping and will fail translation. if (arrayTypeMapping is null) { - return postgresNewArrayExpression; + return pgNewArrayExpression; } elementTypeMapping = arrayTypeMapping.ElementTypeMapping; @@ -988,38 +988,38 @@ static bool IsTextualTypeMapping(RelationalTypeMapping mapping) // An element type mapping was successfully inferred from one of the expressions (there was a column). // Infer the array's type mapping from it. arrayTypeMapping = (NpgsqlArrayTypeMapping?)_typeMappingSource.FindMapping( - postgresNewArrayExpression.Type, + pgNewArrayExpression.Type, elementTypeMapping.StoreType + "[]"); // If the array's CLR type doesn't match the type mapping inferred from the element (e.g. CLR object[] with up-casted // elements). Just return the original expression, which has no type mapping and will fail translation. if (arrayTypeMapping is null) { - return postgresNewArrayExpression; + return pgNewArrayExpression; } } // Now go over all expressions and apply the inferred element type mapping List? newExpressions = null; - for (var i = 0; i < postgresNewArrayExpression.Expressions.Count; i++) + for (var i = 0; i < pgNewArrayExpression.Expressions.Count; i++) { - var expression = postgresNewArrayExpression.Expressions[i]; + var expression = pgNewArrayExpression.Expressions[i]; var newExpression = ApplyTypeMapping(expression, elementTypeMapping); if (newExpression != expression && newExpressions is null) { newExpressions = new List(); for (var j = 0; j < i; j++) { - newExpressions.Add(postgresNewArrayExpression.Expressions[j]); + newExpressions.Add(pgNewArrayExpression.Expressions[j]); } } newExpressions?.Add(newExpression); } - return new PostgresNewArrayExpression( - newExpressions ?? postgresNewArrayExpression.Expressions, - postgresNewArrayExpression.Type, arrayTypeMapping); + return new PgNewArrayExpression( + newExpressions ?? pgNewArrayExpression.Expressions, + pgNewArrayExpression.Type, arrayTypeMapping); } ///