forked from ebhomengo/niki
34 lines
555 B
Go
34 lines
555 B
Go
package database
|
|
|
|
import "strings"
|
|
|
|
type whereClause struct {
|
|
sql strings.Builder
|
|
args []any
|
|
}
|
|
|
|
func (w *whereClause) add(cond string, args ...any) {
|
|
if w.sql.Len() == 0 {
|
|
w.sql.WriteString(" WHERE ")
|
|
} else {
|
|
w.sql.WriteString(" AND ")
|
|
}
|
|
w.sql.WriteString(cond)
|
|
w.args = append(w.args, args...)
|
|
}
|
|
|
|
func (w *whereClause) String() string { return w.sql.String() }
|
|
|
|
func clampLimitOffset(limit, offset int) (int, int) {
|
|
if limit <= 0 {
|
|
limit = 50
|
|
}
|
|
if limit > 100 {
|
|
limit = 100
|
|
}
|
|
if offset < 0 {
|
|
offset = 0
|
|
}
|
|
return limit, offset
|
|
}
|