Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically expand placeholders for IN and lists #29

Open
m0sth8 opened this issue Jul 3, 2016 · 2 comments
Open

Automatically expand placeholders for IN and lists #29

m0sth8 opened this issue Jul 3, 2016 · 2 comments
Labels

Comments

@m0sth8
Copy link

m0sth8 commented Jul 3, 2016

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.

@AlekSi
Copy link
Member

AlekSi commented Jul 4, 2016

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

@AlekSi AlekSi added the triage label Aug 10, 2016
@xaionaro
Copy link
Contributor

xaionaro commented Feb 12, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants