Alexander Ioffe
10/15/2024, 12:44 PMAlexander Ioffe
10/15/2024, 12:46 PMarve
11/01/2024, 1:07 PMselect * from foo where foo.id in = ANY(:idArray)
where :idArray
is bound to a SQL array via connection.createArray() )
Are there any mechanisms in terpal-sql to pass list-like parameters somehow? Or perhaps extension points where i can hook into the parameter binding and do this myself? I couldnāt find any examples for this in the docs š
Any pointers as to where i can start digging would be greatly appreciatedAlexander Ioffe
11/01/2024, 1:51 PMā¦where person.name in ${Params(liofOfNames)}
.arve
11/01/2024, 2:08 PMwhere person.name in (ā¦)
and where person.name = ANY(...)
. The former would require one bound param per element, while the latter expects a single param bound as an array. I know at least when using Postgres there are various perf and limit tradeoffs between the two.
Of course I am beyond happy with either case being supported - just mentioning it in case you want to aim for completenessAlexander Ioffe
11/03/2024, 4:56 AM= Any(...)
I need to support encoders/decoders to/from postgres lists which is possible to do with primitives easily but is much harder to do with user-defined types. I need a couple weeks to figure that out. Supporting regular IN(...)
is much simpler, that I'll have in a couple days. Already have a working implementation.Alexander Ioffe
11/04/2024, 1:31 AM1.0.0.PL-1.1.0
is out supporting IN (...)
clauses. You can see documentation here: https://terpal.io/#/?id=in-clauses
Also, it turns out that if you build a custom wrapper (e.g. value-class) and combine it with @Contextual
and a low-level encoder you can indeed use arbitrary data-structures given your database supports them. Example of how to do that including how to use = ANY(...)
is in the documentation here: https://terpal.io/#/?id=using-array-columns.arve
11/04/2024, 9:19 AMarve
11/04/2024, 10:10 AMqueryOf<T>()
(and actionReturing<T>()
) that takes an extractor function / row mapper, e.g. queryOf<T>( (ResultSet) -> T?))
. Some times itās nice to be allowed to access āunder the hoodā
If i understand correctly this would let you bypass the kotlinx.serialization loop and would be useful in complex cases where you would otherwise have to tailor your entity dataclasses a lot in order to make things work. E.g. custom serializers, @Contextual and @SerialName annotations, etc while still allowing for the frankly delicious interpolation features of Terpal.
val query = Sql("...").queryOf<Member> { row -> Member(
row.int("id"),
row.stringOrNull("name"),
row.zonedDateTime("created_at")
)
}
query.runOn(db)
I realize this might go against the objective / philosophy of Terpal, and Iām not familiar enough with KMP to know how feasible this would be WRT other platforms, but it has proven a very useful pattern for us with kotliquery so far. Consither this a suggestion for improvement rather than a feature request, I donāt want to nag šAlexander Ioffe
11/04/2024, 12:28 PMarve
11/11/2024, 1:21 PM