Skip to content
Merged
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
7 changes: 5 additions & 2 deletions documentation-website/Writerside/topics/Breaking-Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* Migration of kotlinx-datetime from version 6 to version 7. The only package affected is `exposed-kotlin-datetime`. `KotlinInstantColumnType`, and
`Table.timestamp(name: String)` are parametrized with `kotlin.time.Instant` class now. If you need to use `kotlinx.datetime.Instant` with Exposed, you have to
replace usages of `KotlinInstantColumnType` and `Table.timestamp(name: String)` with `XKotlinInstantColumnType` and `Table.xTimestamp(name: String)` respectively,
also the `CurrentTimestamp` constant should be changed with `XCurrentTimestamp`, `CustomTimeStampFunction` with `XCustomTimeStampFunction`.

also the `CurrentTimestamp` constant should be changed with `XCurrentTimestamp`, `CustomTimeStampFunction` with `XCustomTimeStampFunction`.
* The newly introduced `IStatementBuilder` interface has been renamed and deprecated in favor of `StatementBuilder`,
which contains all the original and unchanged methods. It's associated function `buildStatement()` no longer accepts the
deprecated interface as the receiver of its `body` parameter; the parameter expects the new `StatementBuilder` instead.
The same parameter type change applies to the function `explain()`.

## 1.0.0-beta-4

Expand Down
75 changes: 71 additions & 4 deletions exposed-core/api/exposed-core.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,8 @@ open class DeleteStatement(
Replace directly with a table extension function:
`table.deleteWhere(limit) { op }` OR `table.deleteIgnoreWhere(limit) { op }`

Or pass the expected statement to an instance of Executable:
For JDBC:
`DeleteBlockingExecutable(buildStatement { table.deleteWhere(limit, { op }) }).execute(transaction) ?: 0`

FOR R2DBC:
`DeleteSuspendExecutable(buildStatement { table.deleteWhere(limit, { op }) }).execute(transaction) ?: 0`
Or convert the expected statement to an instance of Executable:
`buildStatement { table.deleteWhere(limit, { op }) }.toExecutable().execute(transaction) ?: 0`
""",
level = DeprecationLevel.ERROR
)
Expand All @@ -105,13 +101,8 @@ open class DeleteStatement(
@Deprecated(
message = """
Statement execution has been removed from exposed-core.
Replace directly with a table extension function or pass the expected statement to an instance of Executable:

For JDBC:
`DeleteBlockingExecutable(buildStatement { table.deleteAll() }).execute(transaction) ?: 0`

FOR R2DBC:
`DeleteSuspendExecutable(buildStatement { table.deleteAll() }).execute(transaction) ?: 0`
Replace directly with a table extension function or convert the expected statement to an instance of Executable:
`buildStatement { table.deleteAll() }.toExecutable().execute(transaction) ?: 0`
""",
level = DeprecationLevel.ERROR
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import org.jetbrains.exposed.v1.core.vendors.currentDialect

/** Represents all the DSL methods available when building SQL statements. */
@Suppress("TooManyFunctions")
@Deprecated(
message = "This interface has been renamed and will be removed in future releases.",
replaceWith = ReplaceWith("StatementBuilder", "org.jetbrains.exposed.v1.core.statements.StatementBuilder"),
level = DeprecationLevel.WARNING
)
interface IStatementBuilder {
Comment on lines +9 to 14
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if either option would be better:

  • Immediately set level to ERROR
  • Instead of deprecating, just rename (since it is new as of 1.0.0)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like many people use the 1.0.0-demo-x just like the next versions of Exposed, so I'd say that it's better to keep it like this, and could be better to mark as deprecated and remove later. We still can do breaking changes, but if avoiding it is cheap, we could avoid it.

/**
* Represents the SQL statement that deletes only rows in a table that match the provided [op].
Expand Down Expand Up @@ -121,9 +126,9 @@ interface IStatementBuilder {
fun <T : Table> T.insert(
selectQuery: AbstractQuery<*>,
columns: List<Column<*>>? = null
): org.jetbrains.exposed.v1.core.statements.InsertSelectStatement {
): InsertSelectStatement {
val columnsToReplace = columns ?: this.columns.filter { it.isValidIfAutoIncrement() }
return org.jetbrains.exposed.v1.core.statements.InsertSelectStatement(columnsToReplace, selectQuery, false)
return InsertSelectStatement(columnsToReplace, selectQuery, false)
}

/**
Expand All @@ -140,9 +145,9 @@ interface IStatementBuilder {
fun <T : Table> T.insertIgnore(
selectQuery: AbstractQuery<*>,
columns: List<Column<*>>? = null
): org.jetbrains.exposed.v1.core.statements.InsertSelectStatement {
): InsertSelectStatement {
val columnsToReplace = columns ?: this.columns.filter { it.isValidIfAutoIncrement() }
return org.jetbrains.exposed.v1.core.statements.InsertSelectStatement(columnsToReplace, selectQuery, true)
return InsertSelectStatement(columnsToReplace, selectQuery, true)
}

/**
Expand Down Expand Up @@ -429,12 +434,3 @@ interface IStatementBuilder {
private fun Column<*>.isValidIfAutoIncrement(): Boolean =
!columnType.isAutoInc || autoIncColumnType?.nextValExpression != null
}

/** Builder object for creating SQL statements. Made it private to avoid imports clash */
@Suppress("ForbiddenComment")
// TODO: StatementBuilder -> StatementBuilderImpl, and IStatementBuilder -> StatementBuilder
private object StatementBuilder : IStatementBuilder

// TODO: add documentation for building statements without execution, like in the old DSL
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR #2563

@Suppress("ForbiddenComment", "AnnotationSpacing")
fun <S> buildStatement(body: IStatementBuilder.() -> S): S = body(StatementBuilder)
Comment on lines -439 to -440
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not deprecate this, as lambda parameter would cause overload ambiguity error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just pointing out that the type parameter is not restricted to something like <T, S : Statement<T>>, so technically it could be used like this:

val x: String = buildStatement {
    "hello world"
}

Are we ok with this? Or is there a reason to not type it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine

Loading
Loading