Hi everyone, I just started with Exposed (for addi...
# exposed
p
Hi everyone, I just started with Exposed (for adding persistence in a Ktor api). In one of my entity types I have a property storing a list of image filenames. I see that recent Exposed versions support ArrayColumnType, but I fail to use it properly. Is there an Exposed DAO example how to use ArrayColumnType?
o
Hi, I'd to confirm which database type do you expect to use?
ArrayColumnType
is made to use
array
database type that is supported by Postgres and H2 only (better to recheck). Here is just a simple example of how to use it:
Copy code
object TestTable : IntIdTable() {
        val files = array<String>("files")
    }

    class TestEntity(id: EntityID<Int>) : IntEntity(id) {
        companion object : IntEntityClass<TestEntity>(TestTable)

        var files by TestTable.files
    }

    @Test
    fun test() {
        withTables(TestTable) {
            TestEntity.new {
                files = listOf("f1.pdf", "f2.pdf")
            }

            val entry = TestTable.selectAll().first()
            assertEqualLists(listOf("f1.pdf", "f2.pdf"), entry[TestTable.files])
        }
    }
If you want to store them in another column type (like
varchar
or
text
) you will have to make client side conversion of the data (manually or with
transform
API for example) If you describe your case more detailed, I can try make another example)
p
Thanks Oleg! I intend to use H2. I will try to apply your example in my own types.
👍 1