Skip to content

Commit 371f503

Browse files
dellisdAlec Strong
andauthored
Add support for async drivers (#3168)
* Add async codegen and runtime Add async drivers for R2DBC and sqljs workers * Split sync and async runtime modules * Generate suspend functions for queries Update async runtime to use suspend functions Add Closeable to async runtime Update sqljs worker and r2dbc drivers * Add runtime module tasks to gradle plugin tests * Run spotless * Fix up broken async codegen tests * Pull async gen flag from SqlDelightFile * Add missing prop in intellij tests * Update async mysql integration test Add other async codegen compiler tests * Add async runtime tests Remove async extensions from coroutines-extensions (to revisit later) * Fix spotless errors * Fix broken AsyncTest * Fix js worker test Fix sample builds with new runtime modules * Skip js web worker tests on node * Add driver-async-test Add some brief documentation on implementing async drivers * Disable mingwX86 on driver-async-test * Run spotless (again) * Apply suggestions from code review Co-authored-by: Alec Strong <AlecStrong@users.noreply.github.com> * Remove mingwX86 from runtime-async entirely * Clean things up Add RuntimeTypes class for codegen types Add default async runtime types Remove suspend modifier from generated functions that return an `AsyncQuery` * Make Closeable.close() suspendable * Add missing suspend modifier * Clean up driver-async-test to handle suspend funs * Handle even more suspending test teardowns * Run spotless * Fix one last close function * Fix up and enable remaining js worker tests * Remove driver-async-test Run spotless again again again * Apply suggestions from code review Co-authored-by: Alec Strong <AlecStrong@users.noreply.github.com> * Clean up async runtime Disable async codegen for HSQL Remove unused functions in R2DBC driver Move LogAsyncSqlDriver to tests * Delete async runtime tests Co-authored-by: Alec Strong <AlecStrong@users.noreply.github.com>
1 parent a5ed27d commit 371f503

File tree

110 files changed

+2261
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2261
-132
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ or join the [Jetbrains Platform Slack](https://blog.jetbrains.com/platform/2019/
4242
If you're interested in creating your own driver, you can do so outside of the SQLDelight repository using the `runtime` artifact. To test the driver
4343
you can depend on the `driver-test` and extend `DriverTest` and `TransactionTest` to ensure it works as SQLDelight would expect.
4444

45+
#### Asynchronous Drivers
46+
47+
Drivers that make asynchronous calls can be implemented by using the `runtime-async` artifact.
48+
4549
### Gradle
4650

4751
If you're encountering a gradle issue, start by creating a test fixture in `sqldelight-gradle-plugin/src/test` similar to the other folders there

adapters/primitive-adapters/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ kotlin {
1212
sourceSets {
1313
commonMain {
1414
dependencies {
15-
api project(':runtime')
15+
api project(':runtime:runtime')
1616
}
1717
}
1818
commonTest {

dialects/hsql/src/main/kotlin/app/cash/sqldelight/dialects/hsql/HsqlDialect.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package app.cash.sqldelight.dialects.hsql
22

3+
import app.cash.sqldelight.dialect.api.RuntimeTypes
34
import app.cash.sqldelight.dialect.api.SqlDelightDialect
45
import app.cash.sqldelight.dialect.api.TypeResolver
56
import app.cash.sqldelight.dialects.hsql.grammar.HsqlParserUtil
@@ -13,9 +14,15 @@ import com.squareup.kotlinpoet.ClassName
1314
* Base dialect for JDBC implementations.
1415
*/
1516
class HsqlDialect : SqlDelightDialect {
16-
override val driverType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcDriver")
17-
override val cursorType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcCursor")
18-
override val preparedStatementType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcPreparedStatement")
17+
override val runtimeTypes: RuntimeTypes = RuntimeTypes(
18+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcDriver"),
19+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcCursor"),
20+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcPreparedStatement")
21+
)
22+
23+
override val asyncRuntimeTypes: RuntimeTypes
24+
get() = throw UnsupportedOperationException("HSQL does not support an async driver")
25+
1926
override val icon = AllIcons.Providers.Hsqldb
2027

2128
override fun setup() {

dialects/mysql/src/main/kotlin/app/cash/sqldelight/dialects/mysql/MySqlDialect.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app.cash.sqldelight.dialects.mysql
22

33
import app.cash.sqldelight.dialect.api.ConnectionManager
4+
import app.cash.sqldelight.dialect.api.RuntimeTypes
45
import app.cash.sqldelight.dialect.api.SqlDelightDialect
56
import app.cash.sqldelight.dialect.api.TypeResolver
67
import app.cash.sqldelight.dialects.mysql.grammar.MySqlParserUtil
@@ -16,9 +17,18 @@ import com.squareup.kotlinpoet.ClassName
1617
* Base dialect for JDBC implementations.
1718
*/
1819
class MySqlDialect : SqlDelightDialect {
19-
override val driverType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcDriver")
20-
override val cursorType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcCursor")
21-
override val preparedStatementType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcPreparedStatement")
20+
override val runtimeTypes: RuntimeTypes = RuntimeTypes(
21+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcDriver"),
22+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcCursor"),
23+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcPreparedStatement")
24+
)
25+
26+
override val asyncRuntimeTypes: RuntimeTypes = RuntimeTypes(
27+
ClassName("app.cash.sqldelight.driver.r2dbc", "R2dbcDriver"),
28+
ClassName("app.cash.sqldelight.driver.r2dbc", "R2dbcCursor"),
29+
ClassName("app.cash.sqldelight.driver.r2dbc", "R2dbcPreparedStatement"),
30+
)
31+
2232
override val icon = AllIcons.Providers.Mysql
2333
override val connectionManager: ConnectionManager by lazy { MySqlConnectionManager() }
2434

dialects/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/PostgreSqlDialect.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app.cash.sqldelight.dialects.postgresql
22

33
import app.cash.sqldelight.dialect.api.ConnectionManager
4+
import app.cash.sqldelight.dialect.api.RuntimeTypes
45
import app.cash.sqldelight.dialect.api.SqlDelightDialect
56
import app.cash.sqldelight.dialect.api.TypeResolver
67
import app.cash.sqldelight.dialects.postgresql.grammar.PostgreSqlParserUtil
@@ -15,9 +16,18 @@ import com.squareup.kotlinpoet.ClassName
1516
* Base dialect for JDBC implementations.
1617
*/
1718
class PostgreSqlDialect : SqlDelightDialect {
18-
override val driverType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcDriver")
19-
override val cursorType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcCursor")
20-
override val preparedStatementType = ClassName("app.cash.sqldelight.driver.jdbc", "JdbcPreparedStatement")
19+
override val runtimeTypes: RuntimeTypes = RuntimeTypes(
20+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcDriver"),
21+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcCursor"),
22+
ClassName("app.cash.sqldelight.driver.jdbc", "JdbcPreparedStatement"),
23+
)
24+
25+
override val asyncRuntimeTypes: RuntimeTypes = RuntimeTypes(
26+
ClassName("app.cash.sqldelight.driver.r2dbc", "R2dbcDriver"),
27+
ClassName("app.cash.sqldelight.driver.r2dbc", "R2dbcCursor"),
28+
ClassName("app.cash.sqldelight.driver.r2dbc", "R2dbcPreparedStatement"),
29+
)
30+
2131
override val allowsReferenceCycles = false
2232
override val icon = AllIcons.Providers.Postgresql
2333
override val connectionManager: ConnectionManager by lazy { PostgresConnectionManager() }

dialects/sqlite-3-18/src/main/kotlin/app/cash/sqldelight/dialects/sqlite_3_18/SqliteDialect.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ import com.intellij.ide.plugins.PluginManagerCore
1313
import com.intellij.openapi.application.ApplicationManager
1414
import com.intellij.openapi.extensions.PluginId
1515
import com.intellij.psi.stubs.StubElementTypeHolderEP
16-
import com.squareup.kotlinpoet.ClassName
1716
import timber.log.Timber
1817

1918
/**
2019
* A dialect for SQLite.
2120
*/
2221
open class SqliteDialect : SqlDelightDialect {
23-
override val driverType = ClassName("app.cash.sqldelight.db", "SqlDriver")
24-
override val cursorType = ClassName("app.cash.sqldelight.db", "SqlCursor")
25-
override val preparedStatementType = ClassName("app.cash.sqldelight.db", "SqlPreparedStatement")
2622
override val isSqlite = true
2723
override val icon = AllIcons.Providers.Sqlite
2824
override val migrationStrategy = SqliteMigrationStrategy()

drivers/android-driver/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies {
4545
// workaround for https://youtrack.jetbrains.com/issue/KT-27059
4646
configurations.all {
4747
resolutionStrategy.dependencySubstitution {
48-
substitute module("${project.property("GROUP")}:runtime-jvm:${project.property("VERSION_NAME")}") with project(':runtime')
48+
substitute module("${project.property("GROUP")}:runtime-jvm:${project.property("VERSION_NAME")}") with project(':runtime:runtime')
4949
}
5050
}
5151

drivers/driver-test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kotlin {
1111
sourceSets {
1212
commonMain {
1313
dependencies {
14-
api project(':runtime')
14+
api project(':runtime:runtime')
1515

1616
implementation deps.kotlin.test.common
1717
implementation deps.kotlin.test.commonAnnotations

drivers/jdbc-driver/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
archivesBaseName = 'sqldelight-jdbc-driver'
88

99
dependencies {
10-
api project(':runtime')
10+
api project(':runtime:runtime')
1111
}
1212

1313
apply from: "$rootDir/gradle/gradle-mvn-push.gradle"

drivers/native-driver/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ kotlin {
3030
sourceSets {
3131
commonMain {
3232
dependencies {
33-
api project (':runtime')
33+
api project (':runtime:runtime')
3434
}
3535
}
3636
commonTest {

0 commit comments

Comments
 (0)