-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from ulule/dev
Dev
- Loading branch information
Showing
5 changed files
with
202 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package stmt | ||
|
||
import ( | ||
"github.com/ulule/loukoum/v3/token" | ||
"github.com/ulule/loukoum/v3/types" | ||
) | ||
|
||
// DistinctOn is a distinct on expression. | ||
type DistinctOn struct { | ||
Columns []Column | ||
} | ||
|
||
// NewDistinctOn returns a new DistinctOn instance. | ||
func NewDistinctOn(columns []Column) DistinctOn { | ||
return DistinctOn{ | ||
Columns: columns, | ||
} | ||
} | ||
|
||
// Write exposes statement as a SQL query. | ||
func (distinctOn DistinctOn) Write(ctx types.Context) { | ||
if distinctOn.IsEmpty() { | ||
return | ||
} | ||
ctx.Write(token.DistinctOn.String()) | ||
ctx.Write(" (") | ||
for i := range distinctOn.Columns { | ||
if i != 0 { | ||
ctx.Write(", ") | ||
} | ||
distinctOn.Columns[i].Write(ctx) | ||
} | ||
ctx.Write(")") | ||
} | ||
|
||
// IsEmpty returns true if statement is undefined. | ||
func (distinctOn DistinctOn) IsEmpty() bool { | ||
return len(distinctOn.Columns) == 0 | ||
} | ||
|
||
// Ensure that DistinctOn is a Statement | ||
var _ Statement = DistinctOn{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters