oyvindberg / typo

Typed Postgresql integration for Scala. Hopes to avoid typos
https://oyvindberg.github.io/typo/
MIT License
101 stars 11 forks source link

UUID typecast issues in generated SQL queries #31

Closed KapStorm closed 1 year ago

KapStorm commented 1 year ago

With the same user table and context as #30, doing queries with UUID type (i.g. user_id) doesn't typecast correctly in the sql query, for example

UsersRepoImpl.select.where(_.userId === UsersId(UUID.randomUUID())).toList

throws

Exception in thread "main" java.lang.ExceptionInInitializerError
        at Main.main(Main.scala)
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = character varying
  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
  Position: 128

SQL fragment

UsersRepoImpl.select.where(_.userId === UsersId(UUID.randomUUID())).sql

Some(Fragment(List(NamedParameter(param1,ParameterValue(UsersId(aedb7b6c-c474-44e6-b09a-3f251edb7b46)))),select "user_id","name","last_name","email","password","created_at"::text,"verified_on"::text from public.users
 where user_id = {param1}::VARCHAR
))
oyvindberg commented 1 year ago

Thanks!

The error here is actually in anorm at this line https://github.com/playframework/anorm/blob/main/core/src/main/scala/anorm/ParameterMetaData.scala#L181

For roundtrip time I think I'll work around it, but I'll think a little bit about it.

oyvindberg commented 1 year ago

this will be released in 0.3.0, should be on maven central in some hours