dialect/sql/builder: added FullJoin (#2885)

* dialect/sql/builder: added FullJoin

* fix comment casing

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
Ryo Yamada
2022-08-30 13:39:35 +09:00
committed by GitHub
parent bedbea6665
commit 015effdcc1
2 changed files with 17 additions and 0 deletions

View File

@@ -2331,6 +2331,11 @@ func (s *Selector) RightJoin(t TableView) *Selector {
return s.join("RIGHT JOIN", t)
}
// FullJoin appends a `FULL JOIN` clause to the statement.
func (s *Selector) FullJoin(t TableView) *Selector {
return s.join("FULL JOIN", t)
}
// join adds a join table to the selector with the given kind.
func (s *Selector) join(kind string, t TableView) *Selector {
s.joins = append(s.joins, join{

View File

@@ -853,6 +853,18 @@ func TestBuilder(t *testing.T) {
}(),
wantQuery: "SELECT `g`.`id`, COUNT(`*`) AS `user_count` FROM `groups` AS `g` RIGHT JOIN `user_groups` AS `ug` ON `g`.`id` = `ug`.`group_id` GROUP BY `g`.`id`",
},
{
input: func() Querier {
t1 := Table("groups").As("g")
t2 := Table("user_groups").As("ug")
return Select(t1.C("id"), As(Count("`*`"), "user_count")).
From(t1).
FullJoin(t2).
On(t1.C("id"), t2.C("group_id")).
GroupBy(t1.C("id"))
}(),
wantQuery: "SELECT `g`.`id`, COUNT(`*`) AS `user_count` FROM `groups` AS `g` FULL JOIN `user_groups` AS `ug` ON `g`.`id` = `ug`.`group_id` GROUP BY `g`.`id`",
},
{
input: func() Querier {
t1 := Table("users").As("u")