prepareSql requires that Database.connect() has already been called
- Dominant language
- Kotlin
- Stars
- 9.3k
- Forks
- 798
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 26
Description
I'm trying to use Exposed as a SQL DSL, but *not* as a means to execute the SQL.
The FAQ implies that this is possible: https://github.com/JetBrains/Exposed/wiki/FAQ#q-how-to-get-a-plain-sql-query-which-will-be-executed
However, actually doing it throws:
```
java.lang.IllegalStateException: Please call Database.connect() before using this code
at org.jetbrains.exposed.sql.transactions.NotInitializedManager.currentOrNull(TransactionApi.kt:34)
at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.currentOrNull(TransactionApi.kt:74)
at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.current(TransactionApi.kt:76)
at org.jetbrains.exposed.sql.Column.toSQL(Column.kt:32)
at org.jetbrains.exposed.sql.Query$prepareSQL$$inlined$buildString$lambda$1.invoke(Query.kt:169)
at org.jetbrains.exposed.sql.Query$prepareSQL$$inlined$buildString$lambda$1.invoke(Query.kt:84)
at kotlin.text.StringsKt__StringBuilderKt.appendElement(StringBuilder.kt:58)
at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:2291)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:2308)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:2307)
at org.jetbrains.exposed.sql.Query.prepareSQL(Query.kt:169)
```
My code for this is simply:
```
object AttributesTable : Table() {
val id = uuid("attribute_id").primaryKey()
val version = uuid("version")
val created = datetime("created")
val updated = datetime("updated")
val name = text("name")
val description = text("name")
}
val sql = AttributesTable.select { AttributesTable.id.eq(id) }.prepareSQL(QueryBuilder(false))
```
Contributor guide
Assessment
This issue has not been assessed yet.