Skip to content

Conversation

@bog-walk
Copy link
Member

@bog-walk bog-walk commented Jul 18, 2025

Description

Summary of the change: Rename IStatementBuilder to StatementBuilder and replace usage and add way to get built-in executable instance from statement instance.

Detailed description:

  • What:
    • Rename IStatementBuilder to StatementBuilder + deprecate original
      • Change related usages in buildStatement() and explain()
    • Update KDocs
    • Add Statement.toExecutable() in both modules to avoid user needing to know what executable classes are
    • Add unit tests

Documentation update -> PR #2563


Type of Change

Please mark the relevant options with an "X":

  • Other - Refactor TODO
  • New feature

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:

  • All

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Comment on lines +9 to 14
@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 {
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.

Comment on lines -439 to -440
@Suppress("ForbiddenComment", "AnnotationSpacing")
fun <S> buildStatement(body: IStatementBuilder.() -> S): S = body(StatementBuilder)
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

Comment on lines 56 to +59
fun JdbcTransaction.explain(
analyze: Boolean = false,
options: String? = null,
body: IStatementBuilder.() -> Statement<*>
body: StatementBuilder.() -> Statement<*>
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. Same with r2dbc variant.

Copy link
Member

Choose a reason for hiding this comment

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

let's break it anyway

*
* @throws IllegalStateException If the invoking statement does not have a corresponding built-in executable.
*/
fun <T : Any, S : Statement<T>> S.toExecutable(): BlockingExecutable<T, S> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Decided to add this when writing up the related documentation, because I thought it would be good to be able to take a Statement and then eventually make it into an executable to send to the DB. And it seems odd to force the user to have to look up what the possible executable classes are.

@bog-walk bog-walk requested review from e5l and obabichevjb July 18, 2025 02:25
// 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

Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines -439 to -440
@Suppress("ForbiddenComment", "AnnotationSpacing")
fun <S> buildStatement(body: IStatementBuilder.() -> S): S = body(StatementBuilder)
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

Comment on lines 56 to +59
fun JdbcTransaction.explain(
analyze: Boolean = false,
options: String? = null,
body: IStatementBuilder.() -> Statement<*>
body: StatementBuilder.() -> Statement<*>
Copy link
Member

Choose a reason for hiding this comment

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

let's break it anyway

…erter

- Rename IStatementBuilder to StatementBuilder
- Adjust associated methods
- Add toExecutable() to allow easier conversion
- Add unit tests
@bog-walk bog-walk force-pushed the bog-walk/refactor-statement-builder branch from c596812 to 1b2f6c4 Compare July 25, 2025 03:42
@bog-walk bog-walk merged commit 62409dc into main Jul 25, 2025
5 of 6 checks passed
@bog-walk bog-walk deleted the bog-walk/refactor-statement-builder branch July 25, 2025 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants