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

There should be a way to automatically use ParameterBinding in sql and sqls interpolators #549

Open
kbrowder opened this issue Aug 11, 2016 · 0 comments

Comments

@kbrowder
Copy link
Contributor

So currently if you have a custom binding (which you may want in order to use composite types for instance) it wont work in sql"" or sqls"" interpolators.

I think the way around this is do something like the following:

case class WithBinding(orig: Any, binding: ParameterBinder)
object WithBinding {
  implicit def toWithBinding[A: ParameterBinderFactory](a: A):WithBinding =
    WithBinding(a, implicitly[ParameterBinderFactory[A]].apply(a))
}

And add the following to the SQLInterpolationString class:

def bound_sql[A](params: WithBinding*) = 
  sql[A](params.map(_.binding):_*)

def bsql[A](params: WithBinding*) = bound_sql(params:_*)

def bound_sqls(params: WithBinding*) =
  sqls(params.map(_.binding):_*)

def bsqls(params: WithBinding*)= bound_sqls(params:_*)

Basically this adds new interpolators that only accept parameters that can be implicitly bound. Actually it may be the case that this is reasonable to just change sql/sqls interpolators however this would prevent passing anything in that's not bindable, perhaps that's a good thing, but it would prevent doing things like passing a PGobject directly which may be a bit extreme.

@kbrowder kbrowder changed the title There should be a way to automatically use ParameterBinding in sql sqls interpolators There should be a way to automatically use ParameterBinding in sql and sqls interpolators Aug 11, 2016
@seratch seratch added this to the version 5.0.x milestone Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants