Gustav Elmgren
01/09/2023, 12:42 PMRodrigo Silva
01/13/2023, 7:55 PMException in thread "main" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[BlockingEventLoop@7ca48474, Continuation at org.jetbrains.exposed.sql.transactions.experimental.SuspendedKt$suspendedTransactionAsyncInternal$1.invokeSuspend(Suspended.kt)@59f99ea]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
Ryan Woodcock
01/19/2023, 7:04 AMHaruki
01/26/2023, 5:08 PMobject DatabaseFactory {
fun init() {
Database.connect(
"jdbc:<postgresql://host>:port/5432",
driver = "org.postgresql.Driver",
user = "user",
password = "password"
)
}
}
object ShoppingListItems: Table() {
val id = integer("id").autoIncrement().primaryKey()
val name = varchar("name", length = 255)
val owners = varchar("owners", length = 255)
}
get {
call.respond(ShoppingListItems.select { ShoppingListItems.owners like user }.toList())
}
I am also wondering if we need to create a table. Instead, I want to use a data class like this: val collection = database.getCollection<ShoppingListItem>().
Thank you in advance for your help!maxmello
01/30/2023, 4:36 PMobject
tables and (companion) object
EntityClasses, have classes that are instantiated e.g. in ktor module on app start, which would give the ability to properly pass in dependencies instead of relying on global variables? For example, for my own extensions of Exposed for handling jsonb columns, I need to pass in a Jackson ObjectMapper
. Right now, I have a global object where I set a var on application start, but the Exposed part is the only part of my ktor application not having dependencies properly passed in via constructor params (I don’t use any DI framework).Pavel Naumov
02/06/2023, 10:02 AMMyTable.uShortCol.sum()
truncates result to ushort, obviously.
Any adwise?
I've found an issue on the GitGub https://github.com/JetBrains/Exposed/issues/1035 which seems relevant to me but there's no solutionaazavoykin
02/09/2023, 7:14 AM"limit" >= balance
):
CREATE TABLE IF NOT EXISTS account (
id uuid PRIMARY KEY,
balance DECIMAL(16,2) NOT NULL DEFAULT 0 CHECK (balance >= 0),
"limit" DECIMAL(16,2) NOT NULL DEFAULT 0 CHECK ("limit" >= balance)
);
How could I get the current value of column here?
object AccountTable : Table("account") {
...
val limit: Column<BigDecimal> = decimal("limit", 16, 2)
.default(BigDecimal.ZERO)
.check {it.greaterEq(??????)}
}
Goetz Markgraf
02/10/2023, 2:32 PMShmulik Klein
02/12/2023, 2:16 PMEndre Deak
02/13/2023, 10:23 PMLee Hayeon
02/15/2023, 7:42 PMLee Hayeon
02/15/2023, 7:46 PMMazhar Ibna Zahur
02/16/2023, 7:26 AMdmcg
02/17/2023, 11:31 AMhttps://youtu.be/Uza_dWsNMUs▾
dmcg
02/24/2023, 11:30 AMhttps://youtu.be/Madp0WGq2iA▾
Martin Harvan
02/25/2023, 11:21 PMportion
(EARLY, MID, LATE) and month
and I have data class for it and I would like the DAO to have such field instead of 2 fieldsDantin Kakkar
02/28/2023, 5:20 PMShreck Ye
03/08/2023, 9:41 AMT.J. Tarazevits
03/09/2023, 6:39 PMfindAll()
I am trying to process ~400k records in a cron-job and I don’t want to load all of them into memory at once.
I’ve been googling for Kotlin Exposed Sequence or Kotlin Exposed Iterable
but I am not sure if they actually only pull records on demand from postgres or if they just expose the result of the query as an IterableWxffel
03/16/2023, 5:22 PMWxffel
03/16/2023, 5:33 PMobject Rents : Table("T_Rents") {
val customerId = reference("Customer_Id", Customers.id)
val boatId = reference("Boat_Id", Boats.id)
val dateOfRent = datetime("Date_of_rent")
val dateOfReturn = datetime("Date_of_return")
override val primaryKey = PrimaryKey(customerId, boatId, name = "CustomerAndBoatID")
}
How would we create an entity in this table?Wxffel
03/16/2023, 6:33 PMinteger("Customer_Id").check { it.between(1000, 9999) }.uniqueIndex().entityId().also {
it.defaultValueFun = {
val incrementId = (1000 + Customer.count() + 1).toInt()
EntityIDFunctionProvider.createEntityID(incrementId, this)
}
}
How would one use auto-incrementation within a specified range?
I appreciate any help!André Danielsson
03/16/2023, 7:51 PMColumnType
that will be responsible for encryption and decryption when constructing the queries and returning results. We will need to create multiple instances, one per tenant, so that the appropriate encryption key is used. A snippet demonstrating this idea can be found here: https://pl.kotl.in/9azT-Jlr2
What we found is that this solution works when only using DSL but we are also using DAO to define relations and Entities are constructed by the Exposed library (using reflection?). To my knowledge there is no way of constructing Entities, passing our Table
instances to it. This creates a problem for us as the codebase is using many DAOs today. Does anyone know if there is a way to get around that in any way and we can provide our own "factories" for creating Entity
instances?
Also, I sense that this approach is a bit “hacky” to depend on the tenant inside the DB layer. So this made us look into a second approach.
Approach 2:
We handle encryption/decryption in a repository. To make sure we can’t mix up what is encrypted and what is not we are introducing a new type for encrypted text and then writing a ColumnType
for it to wrap/unwrap the type. We then move the responsibility for encryption/decryption to the repository. We will have different repository instances scoped to tenants so that they can fetch the appropriate encryption key. This is an example how it would look: https://pl.kotl.in/E0ewX3hZ9
This approach will introduce more boilerplate but in this case I think it's not too bad as we will get type safety and it will be impossible to confuse encrypted text with a String.
1. Which would you say is the best approach?
2. Is passing scoped repositories into the ColumnTypes the wrong abstraction and is it better to keep them as simple as possible?Manasseh
03/19/2023, 8:28 PMDaniel
03/20/2023, 8:30 AMManasseh
03/20/2023, 10:45 AMGustav Elmgren
03/22/2023, 8:39 AMDaniel
03/23/2023, 11:34 AMprivate suspend fun <T> executeQuery(timeout: Duration = 3.seconds, block: suspend Transaction.() -> T): T =
withTimeout(timeout) { newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>) { block() } }
public suspend fun test1() = executeQuery(10.seconds) {
with(SomeTable) {
slice(id, other_id, valid_from).select {
(status eq BigDecimal.ONE) and (someFlag eq BigDecimal.ZERO) and
(CurrentDateTime.between(valid_from, valid_to))
}.forEach {
println("$it")
}
}
}
but I am getting Exception in thread "main" java.lang.IllegalStateException: Unexpected value: com.example.MayDatabase$SomeTable.valid_from of org.jetbrains.exposed.sql.Column
I am not sure what I am doing wrong. Very similar code to this worked beforeDaniel
03/23/2023, 1:09 PMHASHBYTES
as CustomFunction
as this:
class HashBytes(algo: Algo, input: Expression<*>) : CustomFunction<ExposedBlob?>("HASHBYTES", BlobColumnType(), QueryParameter(algo.algoName, TextColumnType()), input) {
enum class Algo(val algoName: String) {
MD2("MD2"),
MD4("MD4"),
MD5("MD5"),
SHA("SHA"),
SHA1("SHA1"),
SHA256("SHA2_256"),
SHA512("SHA2_512"),
}
}
but when use I it in slice(someColumn, otherColumn, HashBytes(HashBytes.Algo.MD5, Concat("", someColumn, otherColumn)))
I get the text representation of the hashbytes query in the results instead of the resulting valueEric Thomas
03/29/2023, 10:10 PMaddLogger(StdOutSqlLogger)
but how can I access/interact with this info? ex:
Exposed: transaction { table.select { table.id eq 123 } }
Raw SQL ran against DB: SELECT * FROM TABLE WHERE ID = 123;
//desired result
val executedSql = SELECT * FROM TABLE WHERE ID = 123;
println(executedSql)
How can I access the raw sql executed against the DB?Eric Thomas
03/29/2023, 10:10 PMaddLogger(StdOutSqlLogger)
but how can I access/interact with this info? ex:
Exposed: transaction { table.select { table.id eq 123 } }
Raw SQL ran against DB: SELECT * FROM TABLE WHERE ID = 123;
//desired result
val executedSql = SELECT * FROM TABLE WHERE ID = 123;
println(executedSql)
How can I access the raw sql executed against the DB?Alexey Soshin
03/30/2023, 11:52 AMtransaction {
val rawSQL = table.select { table.id eq 123 }.prepareSQL(this)
println(rawSQL)
}
Eric Thomas
03/30/2023, 3:59 PMobject TestTable : UUIDTable(columnName = "id", name = "test_table") {
val data = uuid("data")
}
class TestRecord(id: EntityID<UUID>) : UUIDEntity(id) {
var data by TestTable.data
}
val rawSQL = transaction {
TestRecord.findById(<id>).prepareSQL(this)
}
println("rawSQL: $rawSQL")