diff --git a/README.md b/README.md index b5ab998..479b0cf 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ val exampleName1 = val exampleName2 = databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() +val examplesExist = databaseClient.selectExpression(exists(Examples.selectAll())) + val deleteRowCount1 = databaseClient.deleteWhere(Examples) { id eq 1 } assert(deleteRowCount1 == 1) val deleteRowCount2 = databaseClient.deleteIgnoreWhere(Examples) { id eq 2 } diff --git a/buildSrc/src/main/kotlin/lib-conventions.gradle.kts b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts index e679e3d..30d8936 100644 --- a/buildSrc/src/main/kotlin/lib-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts @@ -1,5 +1,6 @@ import com.huanshankeji.team.`Shreck Ye` import com.huanshankeji.team.pomForTeamDefaultOpenSource +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { id("conventions") @@ -13,3 +14,7 @@ publishing.publications.getByName("maven") { `Shreck Ye`() } } + +tasks.named>("compileKotlin").configure { + compilerOptions.freeCompilerArgs.add("-opt-in=com.huanshankeji.exposedvertxsqlclient.InternalApi") +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 1cb9160..eb0ab79 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -7,7 +7,6 @@ dependencies { // TODO: remove the Exposed JDBC dependency and the PostgresSQL dependency when there is no need to to generate SQLs with an Exposed transaction runtimeOnly(commonDependencies.exposed.module("jdbc")) api(commonDependencies.kotlinCommon.exposed()) - implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") // TODO remove when code is moved out with(commonDependencies.vertx) { implementation(platformStackDepchain()) @@ -22,10 +21,3 @@ dependencies { implementation(commonDependencies.kotlinCommon.net()) } - -// TODO remove when code is moved out -// for PostgreSQL -dependencies { - runtimeOnly(commonDependencies.postgreSql()) - implementation(commonDependencies.vertx.moduleWithoutVersion("pg-client")) -} diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index 2fdb279..1a55352 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -2,12 +2,10 @@ package com.huanshankeji.exposedvertxsqlclient import arrow.core.* import com.huanshankeji.collections.singleOrNullIfEmpty -import com.huanshankeji.exposedvertxsqlclient.sql.selectExpression import com.huanshankeji.vertx.kotlin.coroutines.coroutineToFuture import com.huanshankeji.vertx.kotlin.sqlclient.executeBatchAwaitForSqlResultSequence import io.vertx.core.buffer.Buffer import io.vertx.kotlin.coroutines.coAwait -import io.vertx.pgclient.PgConnectOptions import io.vertx.sqlclient.* import kotlinx.coroutines.coroutineScope import org.jetbrains.exposed.dao.id.EntityID @@ -65,8 +63,8 @@ fun String.toVertxPgClientPreparedSql(): String { fun Statement<*>.getVertxPgClientPreparedSql(transaction: ExposedTransaction) = prepareSQL(transaction).toVertxPgClientPreparedSql() - -internal fun dbAssert(b: Boolean) { +@InternalApi +fun dbAssert(b: Boolean) { if (!b) throw AssertionError() } @@ -103,7 +101,7 @@ class DatabaseClient( } suspend fun executePlainSql(sql: String): RowSet = - /** Use [SqlClient.preparedQuery] here because of [PgConnectOptions.setCachePreparedStatements]. */ + /** Use [SqlClient.preparedQuery] here because of [SqlConnectOptions.setCachePreparedStatements]. */ vertxSqlClient.preparedQuery(sql).execute().coAwait() suspend fun executePlainSqlUpdate(sql: String): Int = @@ -211,20 +209,20 @@ class DatabaseClient( @Deprecated( - "Use `selectExpression` instead`", + "Use `selectExpression` in the \"sql-dsl\" module instead.", ReplaceWith( "selectExpression(clazz, expression)", "com.huanshankeji.exposedvertxsqlclient.sql.selectExpression" ) ) suspend fun executeExpression(clazz: KClass, expression: Expression): T? = - selectExpression(clazz, expression) + throw NotImplementedError() @Deprecated( - "Use `selectExpression` instead`", + "Use `selectExpression` in the \"sql-dsl\" module instead.", ReplaceWith("selectExpression(expression)", "com.huanshankeji.exposedvertxsqlclient.sql.selectExpression") ) suspend inline fun executeExpression(expression: Expression): T = - selectExpression(expression) + throw NotImplementedError() suspend fun isWorking(): Boolean = try { diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt new file mode 100644 index 0000000..62a302c --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt @@ -0,0 +1,5 @@ +package com.huanshankeji.exposedvertxsqlclient + +@RequiresOptIn("This API is internal in the Exposed Vert.x SQL Client library.") +@Retention(AnnotationRetention.BINARY) +annotation class InternalApi \ No newline at end of file diff --git a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index a87bb29..5e3b590 100644 --- a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -17,6 +17,8 @@ import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.exists +import org.jetbrains.exposed.sql.selectAll object Examples : IntIdTable("examples") { val name = varchar("name", 64) @@ -84,6 +86,8 @@ suspend fun examples(vertx: Vertx) { val exampleName2 = databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() + val examplesExist = databaseClient.selectExpression(exists(Examples.selectAll())) + val deleteRowCount1 = databaseClient.deleteWhere(Examples) { id eq 1 } assert(deleteRowCount1 == 1) val deleteRowCount2 = databaseClient.deleteIgnoreWhere(Examples) { id eq 2 } diff --git a/sql-dsl-with-mapper/build.gradle.kts b/sql-dsl-with-mapper/build.gradle.kts index c83f97f..92d9e90 100644 --- a/sql-dsl-with-mapper/build.gradle.kts +++ b/sql-dsl-with-mapper/build.gradle.kts @@ -7,4 +7,7 @@ plugins { dependencies { with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed implementation(cpnProject(project, ":core")) + implementation(cpnProject(project, ":sql-dsl")) + + implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") // for `updateBuilderSetter`, `DataQueryMapper` and `DataUpdateMapper` } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt similarity index 73% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt rename to sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt index 784ede4..64b4d63 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt +++ b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt @@ -6,18 +6,20 @@ import com.huanshankeji.vertx.sqlclient.datamapping.RowDataQueryMapper import io.vertx.sqlclient.Row import kotlin.reflect.KClass +// TODO all definitions are made private because they are not complete yet + /** * @see ClassPropertyColumnMappings */ // since Kotlin 2.0.0: "'Nothing' property type can't be specified with type alias." -typealias ClassPropertyColumnIndexMappings = Unit // TODO +private typealias ClassPropertyColumnIndexMappings = Unit // TODO -typealias VertxSqlClientRowDataQueryMapper = RowDataQueryMapper +private typealias VertxSqlClientRowDataQueryMapper = RowDataQueryMapper /** * @see ReflectionBasedClassPropertyDataMapper */ -class ReflectionBasedClassPropertyIndexVertxSqlClientRowDataQueryMapper( +private class ReflectionBasedClassPropertyIndexVertxSqlClientRowDataQueryMapper( val clazz: KClass, val classPropertyColumnIndexMappings: ClassPropertyColumnIndexMappings ) : RowDataQueryMapper { diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt rename to sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt rename to sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt diff --git a/sql-dsl/build.gradle.kts b/sql-dsl/build.gradle.kts index c83f97f..febf3bb 100644 --- a/sql-dsl/build.gradle.kts +++ b/sql-dsl/build.gradle.kts @@ -7,4 +7,6 @@ plugins { dependencies { with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed implementation(cpnProject(project, ":core")) + + compileOnly(commonDependencies.kotlinCommon.vertx()) // for `sortDataAndExecuteBatch` } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt rename to sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt