-
Notifications
You must be signed in to change notification settings - Fork 226
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
Support for type casts #893
Comments
How about doing like this? |
How about doing like this: package scalikejdbc
object SQLSyntaxParameterBinderFactory {
def apply[T](syntax: T ⇒ SQLSyntax): ParameterBinderFactory[T] =
(v: T) => SQLSyntaxParameterBinder(syntax(v))
} must be in package scalikejdbc because object CustomType {
implicit val customTypeParameterBinderFactory: ParameterBinderFactory[CustomType] =
SQLSyntaxParameterBinderFactory(v ⇒ sqls"$v::custom_type")
} just change FYI: To read it back you need to define implicit val customTypeTypeBinder: TypeBinder[CustomType] = TypeBinder.string.map(CustomType.fromString) Using this you can write just insertInto(ClassWithCustomType).namedValues(autoNamedValues(c, ClassWithCustomType.column) It could be done without custom Factory: ParameterBinderFactory.sqlSyntaxParameterBinderFactory.contramap[CustomType](v ⇒ sqls"$v::custom_type") but in this case scalikejdbc/scalikejdbc-core/src/main/scala/scalikejdbc/SQLInterpolationString.scala Lines 39 to 53 in 535eb55
therefore simple question mark is used instead of custom sqls
@seratch could that be changed somehow so that anyone can define custom placeholder? |
@sjurco Sorry for my belated reply. The solution you suggested looks fine. I welcome your pull requests to enable the new way. |
It would be great if it is possible to support a custom binding symbol format. For example to generate the following statements with QueryDSL.
insert into message (type) values (cast(? as message_type))
or more postgresql specific
insert into message (type) values (?::message_type)
The would add great support for postgresql enums and other data types
The text was updated successfully, but these errors were encountered: