JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.1k stars 677 forks source link

feat: EXPOSED-248 Support array column type #1986

Closed bog-walk closed 5 months ago

bog-walk commented 5 months ago

Adds a new ArrayColumnType that accepts and returns elements of a List:

object TestTable : Table() {
    val amounts: Column<List<Int>?> = array<Int>("amounts", IntegerColumnType()).nullable()
    val items: Column<List<String?>> = array<String?>("amounts", TextColumnType()).default(emptyList())
    val prices: Column<List<Double>> = array<Double>("prices", DoubleColumnType())
}

Note:

fun arrayList(name: String, columnType: ColumnType, length: Int? = null): Column<List> = registerColumn(name, ArrayColumnType(columnType.apply { nullable = true }, true, length))

And all functions would need to be duplicated or given less restrictive type parameters. If there are any opinions about whether `Array` should be used instead (or add both), please let me know.
- To ensure that each element in the array is processed properly, the user has to supply a delegate column type (on column declaration and in some column functions). This could be seen as too verbose, so functions could be altered to use reflection and assign a column type for primitives, so that the user could choose to omit this argument.

---

Allows maximum array size to be set on column declaration.
Allows array column getter (via index reference) and slicing:
```kt
val somePrices = TestTable.prices.slice(3, 7)
TestTable.select(somePrices).where { TestTable.items[2] eq "Item B" }

Features not supported:

Next steps: