| 291 | type Lt map[string]interface{} |
| 292 | |
| 293 | func (lt Lt) toSql(opposite, orEq bool) (sql string, args []interface{}, err error) { |
| 294 | var ( |
| 295 | exprs []string |
| 296 | opr = "<" |
| 297 | ) |
| 298 | |
| 299 | if opposite { |
| 300 | opr = ">" |
| 301 | } |
| 302 | |
| 303 | if orEq { |
| 304 | opr = fmt.Sprintf("%s%s", opr, "=") |
| 305 | } |
| 306 | |
| 307 | sortedKeys := getSortedKeys(lt) |
| 308 | for _, key := range sortedKeys { |
| 309 | var expr string |
| 310 | val := lt[key] |
| 311 | |
| 312 | switch v := val.(type) { |
| 313 | case driver.Valuer: |
| 314 | if val, err = v.Value(); err != nil { |
| 315 | return |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | if val == nil { |
| 320 | err = fmt.Errorf("cannot use null with less than or greater than operators") |
| 321 | return |
| 322 | } |
| 323 | if isListType(val) { |
| 324 | err = fmt.Errorf("cannot use array or slice with less than or greater than operators") |
| 325 | return |
| 326 | } |
| 327 | expr = fmt.Sprintf("%s %s ?", key, opr) |
| 328 | args = append(args, val) |
| 329 | |
| 330 | exprs = append(exprs, expr) |
| 331 | } |
| 332 | sql = strings.Join(exprs, " AND ") |
| 333 | return |
| 334 | } |
| 335 | |
| 336 | func (lt Lt) ToSql() (sql string, args []interface{}, err error) { |
| 337 | return lt.toSql(false, false) |