I am trying to take advantage of Exposed's type-safe DSL on top of Vert.x SQL Client to have both type-safety and throughput. I know currently Exposed doesn't support any reactive/async/non-blocking database clients yet (see #456, #732, etc.), but a simple workaround is to generate SQLs for them.
Q: How to get a plain SQL query which will be executed? provides a solution using fun prepareSQL(builder: QueryBuilder): String
for Query
s, and for DeleteStatement
s, InsertStatement
s, and UpdateStatment
s, etc., I can use fun prepareSQL(transaction: Transaction): String
and adapt the original library code a little bit to make it generate both plain SQLs and prepared SQLs. However, when I execute the code directly I get the following exception:
Exception in thread "main" java.lang.IllegalStateException: Please call Database.connect() before using this code
Since I don't use Exposed's API but use Vert.x SQL Client's to connect to the database, calling Database.connect
and transaction
would mean a waste of resources. So how do I do this without calling Database.connect
or having a Transaction
? I couldn't figure this out myself since it seems Exposed is too tightly coupled with JDBC and a lot of code's visibility is quite restricted. For example, I also tried creating a dummy no-op Database
but couldn't succeed because it has a private constructor.
In addition, can I also generate SQLs using the DAO API?