fix: query set copy set default module
正在显示
1 个修改的文件
包含
14 行增加
和
1 行删除
| @@ -128,17 +128,19 @@ func (o *QueryOptions) AdditionOptionsByTable(table *domain.Table) *QueryOptions | @@ -128,17 +128,19 @@ func (o *QueryOptions) AdditionOptionsByTable(table *domain.Table) *QueryOptions | ||
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | type Condition struct { | 130 | type Condition struct { |
| 131 | + params QueryOptions | ||
| 131 | domain.Condition | 132 | domain.Condition |
| 132 | Distinct bool | 133 | Distinct bool |
| 133 | DisableFormat bool | 134 | DisableFormat bool |
| 134 | } | 135 | } |
| 135 | 136 | ||
| 136 | func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) { | 137 | func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) { |
| 138 | + c.SetParams(params) | ||
| 137 | if len(c.Like) > 0 { | 139 | if len(c.Like) > 0 { |
| 138 | q.Where(fmt.Sprintf("%v like '%%%v%%'", c.FormatIfNull(params, c.Field), c.Like)) | 140 | q.Where(fmt.Sprintf("%v like '%%%v%%'", c.FormatIfNull(params, c.Field), c.Like)) |
| 139 | } | 141 | } |
| 140 | if len(c.In) > 0 { | 142 | if len(c.In) > 0 { |
| 141 | - q.Where(fmt.Sprintf("cast(%v as string) in %v", c.FormatIfNull(params, c.Field), c.InArgs(c.In))) | 143 | + q.Where(fmt.Sprintf("%v in %v", c.CastType(c.FormatIfNull(params, c.Field), "string"), c.InArgs(c.In))) |
| 142 | } | 144 | } |
| 143 | if len(c.Ex) > 0 { | 145 | if len(c.Ex) > 0 { |
| 144 | in := c.InArgs(c.Ex) | 146 | in := c.InArgs(c.Ex) |
| @@ -173,6 +175,10 @@ func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) { | @@ -173,6 +175,10 @@ func (c Condition) SetWhere(params QueryOptions, q *gorm.DB) { | ||
| 173 | } | 175 | } |
| 174 | } | 176 | } |
| 175 | 177 | ||
| 178 | +func (c *Condition) SetParams(params QueryOptions) { | ||
| 179 | + c.params = params | ||
| 180 | +} | ||
| 181 | + | ||
| 176 | func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string { | 182 | func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string { |
| 177 | if params.Table != nil && params.Table.TableType == domain.ObjectDBTable { | 183 | if params.Table != nil && params.Table.TableType == domain.ObjectDBTable { |
| 178 | return f.SQLName | 184 | return f.SQLName |
| @@ -183,6 +189,13 @@ func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string { | @@ -183,6 +189,13 @@ func (c Condition) FormatIfNull(params QueryOptions, f *domain.Field) string { | ||
| 183 | return f.SQLName | 189 | return f.SQLName |
| 184 | } | 190 | } |
| 185 | 191 | ||
| 192 | +func (c Condition) CastType(sql, t string) string { | ||
| 193 | + if c.params.Table != nil && c.params.Table.TableType == domain.ObjectDBTable { | ||
| 194 | + return sql | ||
| 195 | + } | ||
| 196 | + return fmt.Sprintf("cast(%v as %v)", sql, t) | ||
| 197 | +} | ||
| 198 | + | ||
| 186 | var opMap = map[string]string{ | 199 | var opMap = map[string]string{ |
| 187 | "=": "=", | 200 | "=": "=", |
| 188 | ">": ">", | 201 | ">": ">", |
-
请 注册 或 登录 后发表评论