reform icon indicating copy to clipboard operation
reform copied to clipboard

Automatically expand placeholders for IN and lists

Open m0sth8 opened this issue 7 years ago • 2 comments

reform has different methods to make IN statements now

  1. FindAllFrom(view View, column string, args ...interface{})
  2. 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.

m0sth8 avatar Jul 03 '16 10:07 m0sth8

This will require reflection in runtime, and reform specifically avoids it.

AlekSi avatar Jul 04 '16 11:07 AlekSi

@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.

xaionaro avatar Feb 12 '17 08:02 xaionaro