Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.huanshankeji.exposed

import org.jetbrains.exposed.sql.stringLiteral
import org.jetbrains.exposed.v1.core.stringLiteral

// see: https://stackoverflow.com/questions/68539620/aliasing-count-for-several-columns-in-a-group-by-query-in-exposed
val asterisk = stringLiteral("*")
14 changes: 7 additions & 7 deletions exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.huanshankeji.exposed

import com.huanshankeji.Untested
import org.jetbrains.exposed.sql.ColumnSet
import org.jetbrains.exposed.v1.core.ColumnSet

/**
* To simplify the SQL in some expression queries.
* For example `Dual.slice(exists(Table.emptySlice().select(op))).selectAll()` generates a SQL with no columns which is simpler.
*/
@Deprecated("This causes \"java.lang.IllegalArgumentException: Can't prepare SELECT statement without columns or expressions to retrieve\" in the latest version of Exposed.")
fun ColumnSet.emptySlice() =
@Suppress("DEPRECATION_ERROR")
slice(emptyList())
@Deprecated("This causes \"java.lang.IllegalArgumentException: Can't prepare SELECT statement without columns or expressions to retrieve\" in the latest version of Exposed.", level = DeprecationLevel.ERROR)
fun ColumnSet.emptySlice(): Nothing =
throw UnsupportedOperationException("emptySlice() is not supported in Exposed 1.0.0+ as slice() method was removed. Use proper column selection instead.")

@Untested
fun ColumnSet.selectEmpty() =
select(emptyList())
@Deprecated("This causes \"java.lang.IllegalArgumentException: Can't prepare SELECT statement without columns or expressions to retrieve\" in Exposed 1.0.0+.", level = DeprecationLevel.ERROR)
fun ColumnSet.selectEmpty(): Nothing =
throw UnsupportedOperationException("selectEmpty() is not supported in Exposed 1.0.0+ as it causes IllegalArgumentException. Use a proper column selection instead.")
58 changes: 31 additions & 27 deletions exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package com.huanshankeji.exposed

import com.huanshankeji.InternalApi
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.statements.*
import org.jetbrains.exposed.v1.core.*
import org.jetbrains.exposed.v1.core.statements.*

@InternalApi
const val SELECT_DSL_DEPRECATION_MESSAGE =
Expand All @@ -16,47 +16,51 @@ const val SELECT_DSL_DEPRECATION_MESSAGE =
*/
@Deprecated(
SELECT_DSL_DEPRECATION_MESSAGE,
ReplaceWith("selectAllStatement().where(where)")
ReplaceWith("selectAllStatement().where(where)"),
level = DeprecationLevel.ERROR
)
fun FieldSet.selectStatement(where: WhereOp): Query =
@Suppress("DEPRECATION_ERROR")
select(where)
fun FieldSet.selectStatement(where: WhereOp): Nothing =
throw UnsupportedOperationException("select(where) method removed in Exposed 1.0.0. Use selectAll().where(where) instead.")

/**
* Adapted from [org.jetbrains.exposed.sql.select].
*/
@Deprecated(
SELECT_DSL_DEPRECATION_MESSAGE,
ReplaceWith("selectAllStatement().where(where)")
ReplaceWith("selectAllStatement().where(where)"),
level = DeprecationLevel.ERROR
)
fun FieldSet.selectStatement(where: BuildWhere): Query =
@Suppress("DEPRECATION_ERROR")
select(where)
fun FieldSet.selectStatement(where: BuildWhere): Nothing =
throw UnsupportedOperationException("select(where) method removed in Exposed 1.0.0. Use selectAll().where(where) instead.")

@Deprecated(
SELECT_DSL_DEPRECATION_MESSAGE,
ReplaceWith("selectAllStatement().where(where)")
ReplaceWith("selectAllStatement().where(where)"),
level = DeprecationLevel.ERROR
)
fun <T : FieldSet> T.selectStatementTableAware(where: TableAwareBuildWhere<T>): Query =
selectStatement(where())
fun <T : FieldSet> T.selectStatementTableAware(where: TableAwareBuildWhere<T>): Nothing =
throw UnsupportedOperationException("selectStatement methods removed in Exposed 1.0.0. Use selectAll().where(where) instead.")

/**
* You can also just use [selectAll].
*/
fun FieldSet.selectAllStatement() =
selectAll()
@Deprecated("Use selectAll() directly", ReplaceWith("selectAll()"), level = DeprecationLevel.WARNING)
fun FieldSet.selectAllStatement(): Nothing =
throw UnsupportedOperationException("selectAllStatement() removed in Exposed 1.0.0. Use selectAll() directly.")

/**
* You can also just use [select].
*/
fun ColumnSet.selectStatement(columns: List<Expression<*>>) =
select(columns)
@Deprecated("Use select() directly", ReplaceWith("select(columns)"), level = DeprecationLevel.WARNING)
fun ColumnSet.selectStatement(columns: List<Expression<*>>): Nothing =
throw UnsupportedOperationException("selectStatement() removed in Exposed 1.0.0. Use select() directly.")

/**
* You can also just use [select].
*/
fun ColumnSet.selectStatement(column: Expression<*>, vararg columns: Expression<*>): Query =
select(column, *columns)
@Deprecated("Use select() directly", ReplaceWith("select(column, *columns)"), level = DeprecationLevel.WARNING)
fun ColumnSet.selectStatement(column: Expression<*>, vararg columns: Expression<*>): Nothing =
throw UnsupportedOperationException("selectStatement() removed in Exposed 1.0.0. Use select() directly.")

/**
* @see org.jetbrains.exposed.sql.deleteAll
Expand All @@ -67,23 +71,23 @@ fun Table.deleteAllStatement() =
fun Table.deleteWhereStatement(
op: WhereOp, isIgnore: Boolean = false, limit: Int? = null, offset: Long? = null
): DeleteStatement =
DeleteStatement(this, op, isIgnore, limit, offset)
DeleteStatement(this, op)

/**
* Adapted from [org.jetbrains.exposed.sql.deleteWhere].
*/
fun <T : Table> T.deleteWhereStatement(
limit: Int? = null, offset: Long? = null, op: TableAwareWithSqlExpressionBuilderBuildWhere<T>
): DeleteStatement =
DeleteStatement(this, op(SqlExpressionBuilder), false, limit, offset)
DeleteStatement(this, op(this))

/**
* Adapted from [org.jetbrains.exposed.sql.deleteWhere].
*/
fun <T : Table> T.deleteIgnoreWhereStatement(
limit: Int? = null, offset: Long? = null, op: TableAwareWithSqlExpressionBuilderBuildWhere<T>
): DeleteStatement =
DeleteStatement(this, op(SqlExpressionBuilder), true, limit, offset)
DeleteStatement(this, op(this))

// to access the protected `arguments` in the super class
class HelperInsertStatement<Key : Any>(table: Table, isIgnore: Boolean = false) :
Expand Down Expand Up @@ -112,13 +116,13 @@ fun <T : Table> T.insertIgnoreStatement(body: T.(InsertStatement<Number>) -> Uni
}

fun Table.defaultColumnsForInsertSelect() =
columns.filter { !it.columnType.isAutoInc || it.autoIncColumnType?.nextValExpression != null }
columns.filter { !it.columnType.isAutoInc }

/**
* Adapted from [org.jetbrains.exposed.sql.insert].
*/
fun <T : Table> T.insertSelectStatement(
selectQuery: AbstractQuery<*>,
selectQuery: AbstractQuery,
columns: List<Column<*>> = defaultColumnsForInsertSelect(),
isIgnore: Boolean = false
): InsertSelectStatement =
Expand All @@ -127,7 +131,7 @@ fun <T : Table> T.insertSelectStatement(
fun <T : Table> T.updateStatementWithWhereOp(
where: WhereOp? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit
): UpdateStatement {
val query = UpdateStatement(this, limit, where)
val query = UpdateStatement(this, where)
body(query)
return query
}
Expand All @@ -138,15 +142,15 @@ fun <T : Table> T.updateStatementWithWhereOp(
fun <T : Table> T.updateStatement(
where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit
): UpdateStatement {
val query = UpdateStatement(this, limit, where?.let { SqlExpressionBuilder.it() })
val query = UpdateStatement(this, where?.let { it() })
body(query)
return query
}

fun <T : Table> T.updateStatementTableAware(
where: TableAwareBuildWhere<T>? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit
): UpdateStatement {
val query = UpdateStatement(this, limit, where?.let { it() })
val query = UpdateStatement(this, where?.let { it() })
body(query)
return query
}
Expand Down
9 changes: 4 additions & 5 deletions exposed/src/main/kotlin/com/huanshankeji/exposed/Where.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.huanshankeji.exposed

import org.jetbrains.exposed.sql.ISqlExpressionBuilder
import org.jetbrains.exposed.sql.Op
import org.jetbrains.exposed.sql.SqlExpressionBuilder
import org.jetbrains.exposed.v1.core.ISqlExpressionBuilder
import org.jetbrains.exposed.v1.core.Op

typealias BuildWhere = SqlExpressionBuilder.() -> Op<Boolean>
@Deprecated("Renamed to `WhereBuilder`", ReplaceWith("BuildWhere"/*, "com.huanshankeji.exposed.BuildWhere"*/))
typealias BuildWhere = () -> Op<Boolean>
@Deprecated("Renamed to `BuildWhere`", ReplaceWith("BuildWhere"))
typealias Where = BuildWhere
typealias WhereOp = Op<Boolean>
typealias TableAwareBuildWhere<T/*: FieldSet*/> = T.() -> Op<Boolean>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
package com.huanshankeji.exposed.debug

import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.IColumnType
import org.jetbrains.exposed.sql.Query
import org.jetbrains.exposed.sql.Transaction
import org.jetbrains.exposed.sql.statements.UpdateBuilder
import org.jetbrains.exposed.sql.statements.api.PreparedStatementApi
import org.jetbrains.exposed.v1.core.*
import org.jetbrains.exposed.v1.core.statements.*
import java.io.PrintStream

// TODO remove or update this class
/**
* An [UpdateBuilder] wrapper that print the columns set.
* @deprecated This class doesn't work with Exposed 1.0.0+ due to API changes and will be removed in a future version.
*/
class DebugUpdateBuilderWrapper<out T>(val updateBuilder: UpdateBuilder<T>, val out: PrintStream = System.out) :
UpdateBuilder<T>(updateBuilder.type, updateBuilder.targets) {
override fun arguments(): Iterable<Iterable<Pair<IColumnType<*>, Any?>>> = updateBuilder.arguments()
override fun prepareSQL(transaction: Transaction, prepared: Boolean): String =
updateBuilder.prepareSQL(transaction, prepared)

override fun PreparedStatementApi.executeInternal(transaction: Transaction): T? =
with(updateBuilder) { executeInternal(transaction) }

override fun <S> set(column: Column<S>, value: S) {
out.println("$updateBuilder[$column] = $value")
updateBuilder.set(column, value)
}

/*
override fun <T, S : T, E : Expression<S>> set(column: Column<T>, value: E) {
out.println("$updateBuilder[$column] = $value")
updateBuilder.set(column, value)
}
*/

override fun <S> set(column: Column<S>, value: Query) {
out.println("$updateBuilder[$column] = $value")
updateBuilder.set(column, value)
}
@Deprecated("This class doesn't work with Exposed 1.0.0+ due to API changes and will be removed in a future version.")
class DebugUpdateBuilderWrapper<out T>(val updateBuilder: UpdateBuilder<T>, val out: PrintStream = System.out) {
@Deprecated("This method doesn't work with Exposed 1.0.0+ due to API changes.", level = DeprecationLevel.ERROR)
fun createWrapper(): Nothing =
throw UnsupportedOperationException("DebugUpdateBuilderWrapper is not compatible with Exposed 1.0.0+. Please use alternative debugging methods.")
}