Is it possible to store the raw Sql statements Exposed passes to the DB in a variable? I'm aware logging the statements via
addLogger(StdOutSqlLogger)
but how can I access/interact with this info? ex:
Copy code
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?
Note that this will not execute your SQL, it will only print it
e
Eric Thomas
03/30/2023, 3:59 PM
Thank you very much, that worked! Is it possible to do the same thing from an entity?
ex:
Copy code
object 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")
Eric Thomas
03/30/2023, 4:00 PM
@Alexey Soshin
a
Alexey Soshin
03/31/2023, 10:22 AM
Not when you use
findById
, since it already returns you an Entity back, not a query
Alexey Soshin
03/31/2023, 10:23 AM
Also note that not all
findById
invocations will results in a query: some may find the data in cache