zio / zio-sql

Type-safe, composable SQL for ZIO applications
https://zio.dev/zio-sql/
Apache License 2.0
236 stars 116 forks source link

Add support for var-arg db functions #439

Open jczuchnowski opened 3 years ago

jczuchnowski commented 3 years ago

Add support for var-arg db functions like format or concat.

jgoday commented 3 years ago

@jczuchnowski can this implementation be a valid solution? (https://github.com/jgoday/zio-sql/tree/feature_variadic_args)

It would allow to call custom procedure/function with N different typed args.

val customFn = variadicFunc[String]("concat_ws")
val query    = select(customFn(", ", fName, lName)) from customers

A pending improvement could be to allow define variadicFunc with argument type parameters

val customFn = variadicFunc[String, Int, String]("custom_function")
val query    = select(customFn(name, id)) from table

but I can only imagine implementing this with macros ...