作者 yangfu

fix: query set copy set default module

... ... @@ -128,17 +128,19 @@ func (o *QueryOptions) AdditionOptionsByTable(table *domain.Table) *QueryOptions
}
type Condition struct {
params QueryOptions
domain.Condition
Distinct bool
DisableFormat bool
}
func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) {
c.SetParams(params)
if len(c.Like) > 0 {
q.Where(fmt.Sprintf("%v like '%%%v%%'", c.FormatIfNull(params, c.Field), c.Like))
}
if len(c.In) > 0 {
q.Where(fmt.Sprintf("cast(%v as string) in %v", c.FormatIfNull(params, c.Field), c.InArgs(c.In)))
q.Where(fmt.Sprintf("%v in %v", c.CastType(c.FormatIfNull(params, c.Field), "string"), c.InArgs(c.In)))
}
if len(c.Ex) > 0 {
in := c.InArgs(c.Ex)
... ... @@ -173,6 +175,10 @@ func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) {
}
}
func (c *Condition) SetParams(params QueryOptions) {
c.params = params
}
func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string {
if params.Table != nil && params.Table.TableType == domain.ObjectDBTable {
return f.SQLName
... ... @@ -183,6 +189,13 @@ func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string {
return f.SQLName
}
func (c Condition) CastType(sql, t string) string {
if c.params.Table != nil && c.params.Table.TableType == domain.ObjectDBTable {
return sql
}
return fmt.Sprintf("cast(%v as %v)", sql, t)
}
var opMap = map[string]string{
"=": "=",
">": ">",
... ...