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

Readme FAQ #26

Merged
merged 2 commits into from
May 23, 2024
Merged

Readme FAQ #26

merged 2 commits into from
May 23, 2024

Conversation

AugustNagro
Copy link
Owner

@AugustNagro AugustNagro commented May 21, 2024

Closes #24

@AugustNagro AugustNagro merged commit 9a9a322 into master May 23, 2024
@alwins0n
Copy link

After re-reading it on the projects main page, I wanted to add one minor correction: Database DO support nested/embedded structures such as postgres composite type, so it's wrong to state that they don't or only support flat structures.

e.g. https://www.postgresql.org/docs/current/sql-createtype.html

@AugustNagro
Copy link
Owner Author

That's a good point.. I will re-word.

For Postgres, it appears that the JDBC driver does not support user-defined types pgjdbc/pgjdbc#641

However, I WOULD support this feature, user-defined type support, for databases that support them, IF the official JDBC driver also gains support.

As it stands, there is a work-around one could use for UDTs in Postgres + Magnum. For the embedded class, you can define a custom DBCodec that grabs the column as a Pgobject , then does some custom deserialization (have not tested):

  given EmbeddedAddressCodec: DbCodec[Address] with
    def queryRepr: String = "?"
    val cols: IArray[Int] = IArray(Types.JAVA_OBJECT)
    def readSingle(resultSet: ResultSet, pos: Int): Address =
      val obj = resultSet.getObject(pos, classOf[PGobject])
      customDeser(obj.getValue)
    def writeSingle(entity: Address, ps: PreparedStatement, pos: Int): Unit =
      val res = customSer(entity)
      ps.setObject(pos, res)

You could then even make it generic.

@AugustNagro
Copy link
Owner Author

You could then even make it generic.

Maybe by defining

trait UdtDbCodec[A] extends DbCodec[A]

@alwins0n
Copy link

Thanks for the hint. I will fiddle a little with your library. Maybe I can extend the functionality to my requirements. After all I should always be able to supply a custom DbCodec right?

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

Successfully merging this pull request may close these issues.

DbCodec is not recursively applied
2 participants