Is it possible to store the raw Sql statements Exp...
# exposed
e
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?
a
Hi Eric, You can do something like this:
Copy code
transaction { 
    val rawSQL = table.select { table.id eq 123 }.prepareSQL(this) 

    println(rawSQL)
}
Note that this will not execute your SQL, it will only print it
e
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")
@Alexey Soshin
a
Not when you use
findById
, since it already returns you an Entity back, not a query
Also note that not all
findById
invocations will results in a query: some may find the data in cache
491 Views