Skip to content

Commit

Permalink
feat: EXPOSED-494 Inline DSL statement and query functions
Browse files Browse the repository at this point in the history
- Introduce back original extension functions (with nullable parameters) as deprecated
versions.
- Update .api dump
  • Loading branch information
bog-walk committed Oct 28, 2024
1 parent 0f1d5af commit 6e78edf
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
12 changes: 12 additions & 0 deletions exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1827,10 +1827,14 @@ public final class org/jetbrains/exposed/sql/QueriesKt {
public static final fun deleteIgnoreWhere (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;)I
public static synthetic fun deleteIgnoreWhere$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I
public static synthetic fun deleteIgnoreWhere$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I
public static final fun deleteJoinNullableParam (Lorg/jetbrains/exposed/sql/Join;Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Table;ZLjava/lang/Integer;Lkotlin/jvm/functions/Function1;)I
public static synthetic fun deleteJoinNullableParam$default (Lorg/jetbrains/exposed/sql/Join;Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Table;ZLjava/lang/Integer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)I
public static final fun deleteReturning (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static final fun deleteReturning (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static synthetic fun deleteReturning$default (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static synthetic fun deleteReturning$default (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static final fun deleteReturningNullableParam (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static synthetic fun deleteReturningNullableParam$default (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static final fun deleteWhere (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;)I
public static final fun deleteWhere (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;)I
public static synthetic fun deleteWhere$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I
Expand All @@ -1849,6 +1853,8 @@ public final class org/jetbrains/exposed/sql/QueriesKt {
public static final fun mergeFrom (Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/QueryAlias;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/statements/MergeSelectStatement;
public static final fun mergeFrom (Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/statements/MergeTableStatement;
public static final fun mergeFrom (Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/statements/MergeTableStatement;
public static final fun mergeFromNullableParam (Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/statements/MergeTableStatement;
public static synthetic fun mergeFromNullableParam$default (Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/MergeTableStatement;
public static final fun replace (Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/ReplaceStatement;
public static final fun replace (Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;)Ljava/lang/Integer;
public static synthetic fun replace$default (Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;ILjava/lang/Object;)Ljava/lang/Integer;
Expand All @@ -1873,10 +1879,16 @@ public final class org/jetbrains/exposed/sql/QueriesKt {
public static synthetic fun update$default (Lorg/jetbrains/exposed/sql/Join;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)I
public static synthetic fun update$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I
public static synthetic fun update$default (Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I
public static final fun updateJoinNullableParam (Lorg/jetbrains/exposed/sql/Join;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function1;)I
public static synthetic fun updateJoinNullableParam$default (Lorg/jetbrains/exposed/sql/Join;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)I
public static final fun updateNullableParam (Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;)I
public static synthetic fun updateNullableParam$default (Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I
public static final fun updateReturning (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static final fun updateReturning (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static synthetic fun updateReturning$default (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static synthetic fun updateReturning$default (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static final fun updateReturningNullableParam (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static synthetic fun updateReturningNullableParam$default (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/ReturningStatement;
public static final fun upsert (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/UpsertStatement;
public static final fun upsert (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Lkotlin/jvm/functions/Function2;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/UpsertStatement;
public static synthetic fun upsert$default (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/UpsertStatement;
Expand Down
91 changes: 91 additions & 0 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ inline fun <T : Table> T.deleteIgnoreWhere(
fun Table.deleteAll(): Int =
DeleteStatement.all(TransactionManager.current(), this@deleteAll)

@Deprecated(
"This `deleteReturning()` with a nullable `where` parameter will be removed in future releases. Please leave a comment on " +
"[YouTrack](https://youtrack.jetbrains.com/issue/EXPOSED-494/Inline-DSL-statement-and-query-functions) " +
"with a use-case if a nullable condition cannot be replaced with the new `deleteReturning()` overloads.",
ReplaceWith("deleteReturning(returning)"),
DeprecationLevel.WARNING
)
@JvmName("deleteReturningNullableParam")
fun <T : Table> T.deleteReturning(
returning: List<Expression<*>> = columns,
where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null
): ReturningStatement {
return where?.let { deleteReturning(returning, it) } ?: deleteReturning(returning)
}

/**
* Represents the SQL statement that deletes rows in a table and returns specified data from the deleted rows.
*
Expand Down Expand Up @@ -192,6 +207,26 @@ fun <T : Table> T.deleteReturning(
return ReturningStatement(this, returning, delete)
}

@Deprecated(
"This `Join.delete()` with a nullable `where` parameter will be removed in future releases. Please leave a comment on " +
"[YouTrack](https://youtrack.jetbrains.com/issue/EXPOSED-494/Inline-DSL-statement-and-query-functions) " +
"with a use-case if a nullable condition cannot be replaced with the new `Join.delete()` overloads.",
ReplaceWith("delete(targetTable, targetTables = targetTables, ignore, limit)"),
DeprecationLevel.WARNING
)
@JvmName("deleteJoinNullableParam")
fun Join.delete(
targetTable: Table,
vararg targetTables: Table,
ignore: Boolean = false,
limit: Int? = null,
where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null
): Int {
return where?.let {
delete(targetTable, targetTables = targetTables, ignore, limit, it)
} ?: delete(targetTable, targetTables = targetTables, ignore, limit)
}

/**
* Represents the SQL statement that deletes rows from a table in a join relation.
*
Expand Down Expand Up @@ -528,6 +563,18 @@ inline fun <T : Table> T.insertReturning(
return ReturningStatement(this, returning, insert)
}

@Deprecated(
"This `update()` with a nullable `where` parameter will be removed in future releases. Please leave a comment on " +
"[YouTrack](https://youtrack.jetbrains.com/issue/EXPOSED-494/Inline-DSL-statement-and-query-functions) " +
"with a use-case if a nullable condition cannot be replaced with the new `update()` overloads.",
ReplaceWith("update(limit = limit) { body.invoke() }"),
DeprecationLevel.WARNING
)
@JvmName("updateNullableParam")
fun <T : Table> T.update(where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit): Int {
return where?.let { update(it, limit, body) } ?: update(limit, body)
}

/**
* Represents the SQL statement that updates rows of a table.
*
Expand Down Expand Up @@ -562,6 +609,18 @@ inline fun <T : Table> T.update(
return query.execute(TransactionManager.current()) ?: 0
}

@Deprecated(
"This `Join.update()` with a nullable `where` parameter will be removed in future releases. Please leave a comment on " +
"[YouTrack](https://youtrack.jetbrains.com/issue/EXPOSED-494/Inline-DSL-statement-and-query-functions) " +
"with a use-case if a nullable condition cannot be replaced with the new `Join.update()` overloads.",
ReplaceWith("update(limit = limit) { body.invoke() }"),
DeprecationLevel.WARNING
)
@JvmName("updateJoinNullableParam")
fun Join.update(where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null, limit: Int? = null, body: (UpdateStatement) -> Unit): Int {
return where?.let { update(it, limit, body) } ?: update(limit, body)
}

/**
* Represents the SQL statement that updates rows of a join relation.
*
Expand Down Expand Up @@ -596,6 +655,22 @@ inline fun Join.update(
return query.execute(TransactionManager.current()) ?: 0
}

@Deprecated(
"This `updateReturning()` with a nullable `where` parameter will be removed in future releases. Please leave a comment on " +
"[YouTrack](https://youtrack.jetbrains.com/issue/EXPOSED-494/Inline-DSL-statement-and-query-functions) " +
"with a use-case if a nullable condition cannot be replaced with the new `updateReturning()` overloads.",
ReplaceWith("updateReturning(returning) { body.invoke() }"),
DeprecationLevel.WARNING
)
@JvmName("updateReturningNullableParam")
fun <T : Table> T.updateReturning(
returning: List<Expression<*>> = columns,
where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
body: T.(UpdateStatement) -> Unit
): ReturningStatement {
return where?.let { updateReturning(returning, it, body) } ?: updateReturning(returning, body)
}

/**
* Represents the SQL statement that updates rows of a table and returns specified data from the updated rows.
*
Expand Down Expand Up @@ -856,6 +931,22 @@ private fun <T : Table, E> T.batchUpsert(
*/
fun Table.exists(): Boolean = currentDialect.tableExists(this)

@Deprecated(
"This `mergeFrom()` with a nullable `on` parameter will be removed in future releases. Please leave a comment on " +
"[YouTrack](https://youtrack.jetbrains.com/issue/EXPOSED-494/Inline-DSL-statement-and-query-functions) " +
"with a use-case if a nullable condition cannot be replaced with the new `mergeFrom()` overloads.",
ReplaceWith("mergeFrom(source) { body.invoke() }"),
DeprecationLevel.WARNING
)
@JvmName("mergeFromNullableParam")
fun <D : Table, S : Table> D.mergeFrom(
source: S,
on: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
body: MergeTableStatement.() -> Unit
): MergeTableStatement {
return on?.let { mergeFrom(source, it, body) } ?: mergeFrom(source, body)
}

/**
* Performs an SQL MERGE operation to insert, update, or delete records in the target table based on
* a comparison with a source table.
Expand Down

0 comments on commit 6e78edf

Please sign in to comment.