reform
reform copied to clipboard
Automatically expand placeholders for IN and lists
reform has different methods to make IN statements now
- FindAllFrom(view View, column string, args ...interface{})
- SelectRows(view View, tail string, args ...interface{})
The first one handles just one IN for a column, In the second I have to make placeholders for IN by myself.
What I want is the same logic as in the first case, but reform should automatically expand args element to $1, $2 if this element has a slice value.
This will require reflection in runtime, and reform specifically avoids it.
@AlekSi, I remember on a meetup you said that you avoid reflection to avoid "interface{}" (to work with specific types, instead -- to avoid runtime errors). But "args" is already []interface{} :)
Also you don't really required in reflection. You can use something like:
switch arg := argI.(type) {
case []int:
[an implementation for slices]
case []int64:
[an implementation for slices]
case []float32:
[an implementation for slices]
case []float64:
[an implementation for slices]
case []string:
[an implementation for slices]
case []time.Time:
[an implementation for slices]
case []interface{}:
[an implementation for slices]
default:
[old implementation]
}
Moreover, the most serious problem is not reflection, but replacing the placeholder in the query to a set of placeholders.