(t *testing.T)
| 2077 | } |
| 2078 | |
| 2079 | func TestWindowFunction(t *testing.T) { |
| 2080 | posts := Table("posts") |
| 2081 | base := Select(posts.Columns("id", "content", "author_id")...). |
| 2082 | From(posts). |
| 2083 | Where(EQ("active", true)) |
| 2084 | with := With("active_posts"). |
| 2085 | As(base). |
| 2086 | With("selected_posts"). |
| 2087 | As( |
| 2088 | Select(). |
| 2089 | AppendSelect("*"). |
| 2090 | AppendSelectExprAs( |
| 2091 | RowNumber().PartitionBy("author_id").OrderBy("id").OrderExpr(Expr("f(`s`)")), |
| 2092 | "row_number", |
| 2093 | ). |
| 2094 | From(Table("active_posts")), |
| 2095 | ) |
| 2096 | query, args := Select("*").From(Table("selected_posts")).Where(LTE("row_number", 2)).Prefix(with).Query() |
| 2097 | require.Equal(t, "WITH `active_posts` AS (SELECT `posts`.`id`, `posts`.`content`, `posts`.`author_id` FROM `posts` WHERE `active`), `selected_posts` AS (SELECT *, (ROW_NUMBER() OVER (PARTITION BY `author_id` ORDER BY `id`, f(`s`))) AS `row_number` FROM `active_posts`) SELECT * FROM `selected_posts` WHERE `row_number` <= ?", query) |
| 2098 | require.Equal(t, []any{2}, args) |
| 2099 | } |
| 2100 | |
| 2101 | func TestWindowFunction_Select(t *testing.T) { |
| 2102 | posts := Table("posts") |
nothing calls this directly
no test coverage detected
searching dependent graphs…