add SeqFilter
This commit is contained in:
parent
dbcb6fe173
commit
3dd33af2d6
24
filter.go
24
filter.go
|
@ -1,6 +1,9 @@
|
|||
package core
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Filter is an interface to filter SQL
|
||||
type Filter interface {
|
||||
|
@ -40,3 +43,22 @@ func (i *IdFilter) Do(sql string, dialect Dialect, table *Table) string {
|
|||
}
|
||||
return sql
|
||||
}
|
||||
|
||||
// SeqFilter filter SQL replace ?, ? ... to $1, $2 ...
|
||||
type SeqFilter struct {
|
||||
Prefix string
|
||||
Start int
|
||||
}
|
||||
|
||||
func (s *SeqFilter) Do(sql string, dialect Dialect, table *Table) string {
|
||||
segs := strings.Split(sql, "?")
|
||||
size := len(segs)
|
||||
res := ""
|
||||
for i, c := range segs {
|
||||
if i < size-1 {
|
||||
res += c + fmt.Sprintf("%s%v", s.Prefix, i+s.Start)
|
||||
}
|
||||
}
|
||||
res += segs[size-1]
|
||||
return res
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue