kotlin-orm / ktorm

A lightweight ORM framework for Kotlin with strong-typed SQL DSL and sequence APIs.
https://www.ktorm.org
Apache License 2.0
2.1k stars 148 forks source link

How I can transform field as ColumnTransformer in hibernate? #583

Open maxtar opened 11 hours ago

maxtar commented 11 hours ago

We are use Postgres DB. And one table has encrypted field. For encrypting/decrypting this field in hibernate uses ColumnTransformer annotation like this:

@ColumnTransformer(
        read = "pgp_sym_decrypt( field, current_setting('encrypt.key'))",
        write = "pgp_sym_encrypt( ?,  current_setting('encrypt.key'))"
    )

how I can use something like this in ktorm?

vincentlauvlwj commented 11 hours ago

Perform your transformation in a custom SqlType implementation.

public object CustomSqlType : SqlType<String>(Types.VARCHAR, "varchar") {

    override fun doSetParameter(ps: PreparedStatement, index: Int, parameter: String) {

    }

    override fun doGetResult(rs: ResultSet, index: Int): String? {

    }
}
maxtar commented 11 hours ago

And what I need write in transformation? SQL? Sql request for this field looks like

SELECT pgp_sym_decrypt(field, CURRENT_SETTING('encrypt.key')),
FROM table;