Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion select.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ func (b SelectBuilder) RemoveColumns() SelectBuilder {
// Column adds a result column to the query.
// Unlike Columns, Column accepts args which will be bound to placeholders in
// the columns string, for example:
// Column("IF(col IN ("+squirrel.Placeholders(3)+"), 1, 0) as col", 1, 2, 3)
//
// Column("IF(col IN ("+squirrel.Placeholders(3)+"), 1, 0) as col", 1, 2, 3)
func (b SelectBuilder) Column(column interface{}, args ...interface{}) SelectBuilder {
return builder.Append(b, "Columns", newPart(column, args...)).(SelectBuilder)
}
Expand Down Expand Up @@ -362,6 +363,10 @@ func (b SelectBuilder) Where(pred interface{}, args ...interface{}) SelectBuilde
return builder.Append(b, "WhereParts", newWherePart(pred, args...)).(SelectBuilder)
}

func (b SelectBuilder) NotDeleted() SelectBuilder {
return b.Where("deleted_at IS NULL")
}

// GroupBy adds GROUP BY expressions to the query.
func (b SelectBuilder) GroupBy(groupBys ...string) SelectBuilder {
return builder.Extend(b, "GroupBys", groupBys).(SelectBuilder)
Expand Down
9 changes: 9 additions & 0 deletions select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func TestAsOfSystemTime(t *testing.T) {
assert.Equal(t, expectedArgs, args)
}

func TestNotDeleted(t *testing.T) {
b := Select("test").Where(Eq{"f4": true}).NotDeleted()
query, args, _ := b.ToSql()
expectedSql := `SELECT test WHERE f4 = ? AND deleted_at IS NULL`
expectedArgs := []interface{}{true}
assert.Equal(t, expectedSql, query)
assert.Equal(t, expectedArgs, args)
}

func TestSelectBuilderFromSelect(t *testing.T) {
subQ := Select("c").From("d").Where(Eq{"i": 0})
b := Select("a", "b").FromSelect(subQ, "subq")
Expand Down