Beispiel #1
0
        public void HandleJoinedOneToManyPaginated_WhenCalledWithOffsetPagination_ReturnsPagedJoinString()
        {
            var dialect         = new PostgresSqlDialect();
            var compilerContext = new SqlCompilerContext(new SqlCompiler(dialect));
            var parent          = new SqlTable(null, null, "products", "products", "products", new Dictionary <string, object>(), true);

            parent.AddColumn("id", "id", "id", true);
            var node = new SqlTable(null, null, "variants", "variants", "variants", new Dictionary <string, object>(), true)
            {
                Join    = (join, _, __, ___) => join.On("id", "productId"),
                OrderBy = new OrderBy("variants", "id", SortDirection.Ascending),
                Where   = (where, _, __, ___) => where.Column("id", 1, "<>")
            };

            node.AddColumn("id", "id", "id", true);

            var arguments = new Dictionary <string, object>();
            var context   = new ResolveFieldContext();
            var tables    = new List <string>();

            dialect.HandleJoinedOneToManyPaginated(parent, node, arguments, context, tables, compilerContext,
                                                   "\"products\".\"id\" = \"variants\".\"productId\"");

            tables.Should()
            .Contain("LEFT JOIN LATERAL (\n  SELECT \"variants\".*, COUNT(*) OVER () AS \"$total\"\n  FROM \"variants\" \"variants\"\n  WHERE \"products\".\"id\" = \"variants\".\"productId\" AND \"variants\".\"id\" <> @p0\n  ORDER BY \"variants\".\"id\" ASC\n  LIMIT ALL OFFSET 0\n) \"variants\" ON \"products\".\"id\" = \"variants\".\"productId\"");
        }
Beispiel #2
0
        public void HandleJoinedOneToManyPaginated_WhenCalledWithKeysetPagination_ReturnsPagedJoinString()
        {
            var dialect         = new PostgresSqlDialect();
            var compilerContext = new SqlCompilerContext(new SqlCompiler(dialect));
            var parent          = new SqlTable(null, null, "products", "products", "products", new Dictionary <string, object>(), true);

            parent.AddColumn("id", "id", "id", true);
            var node = new SqlTable(null, null, "variants", "variants", "variants", new Dictionary <string, object>(), true)
            {
                Join    = (join, _, __, ___) => join.On("id", "productId"),
                OrderBy = new OrderBy("products", "id", SortDirection.Ascending),
                SortKey = new SortKey("products", "id", "id", typeof(int), SortDirection.Ascending),
                Where   = (where, _, __, ___) => where.Column("id", 1, "<>")
            };

            node.AddColumn("id", "id", "id", true);

            var arguments = new Dictionary <string, object>();
            var context   = new ResolveFieldContext();
            var tables    = new List <string>();

            dialect.HandleJoinedOneToManyPaginated(parent, node, arguments, context, tables, compilerContext,
                                                   "\"products\".\"id\" = \"variants\".\"productId\"");

            tables.Should()
            .Contain(@"LEFT JOIN LATERAL (
  SELECT ""variants"".*
  FROM ""variants"" ""variants""
  WHERE ""products"".""id"" = ""variants"".""productId"" AND ""variants"".""id"" <> @p0
  ORDER BY ""variants"".""id"" ASC
  LIMIT ALL
) ""variants"" ON ""products"".""id"" = ""variants"".""productId""");
        }
Beispiel #3
0
        public void HandleJoinedOneToManyPaginated_WhenCalledWithKeysetPaginationAndFirstAndAfter_ReturnsPagedJoinString()
        {
            var dialect         = new PostgresSqlDialect();
            var compilerContext = new SqlCompilerContext(new SqlCompiler(dialect));
            var parent          = new SqlTable(null, null, "products", "products", "products", new Dictionary <string, object>(),
                                               true);

            parent.AddColumn("id", "id", "id", true);
            var node = new SqlTable(null, null, "variants", "variants", "variants", new Dictionary <string, object>(),
                                    true)
            {
                Join    = (join, _, __, ___) => join.On("id", "productId"),
                SortKey = new SortKey("products", "id", "id", typeof(int), SortDirection.Descending),
                Where   = (where, _, __, ___) => where.Column("id", 1, "<>")
            };

            node.AddColumn("id", "id", "id", true);

            var arguments = new Dictionary <string, object>
            {
                { "first", 2 },
                { "after", Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new { id = 1 }))) }
            };
            var context = new ResolveFieldContext();
            var tables  = new List <string>();

            dialect.HandleJoinedOneToManyPaginated(parent, node, arguments, context, tables, compilerContext,
                                                   "\"products\".\"id\" = \"variants\".\"productId\"");

            using (new AssertionScope())
            {
                tables.Should()
                .Contain(@"LEFT JOIN LATERAL (
  SELECT ""variants"".*
  FROM ""variants"" ""variants""
  WHERE ""products"".""id"" = ""variants"".""productId"" AND ""variants"".""id"" <> @p0 AND ""variants"".""id"" < @p1
  ORDER BY ""variants"".""id"" DESC
  LIMIT 3
) ""variants"" ON ""products"".""id"" = ""variants"".""productId""");

                compilerContext.Parameters.Should()
                .BeEquivalentTo(new Dictionary <string, object>
                {
                    { "@p0", 1 },
                    { "@p1", 1 }
                });
            }
        }