Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SqlPreparedStatement to SqlDriver as generic type #3717

Open
hfhbd opened this issue Dec 4, 2022 · 0 comments
Open

Add SqlPreparedStatement to SqlDriver as generic type #3717

hfhbd opened this issue Dec 4, 2022 · 0 comments
Labels

Comments

@hfhbd
Copy link
Collaborator

hfhbd commented Dec 4, 2022

Description

Each driver supports different bind options, JDBC supports array, objects and so on. At the moment, you use the SqlPreparedStatement interface but this requires a cast in the binders parameter:

override fun execute(
  ...,
  binders: (SqlPreparedStatement.() -> Unit)? // base interface, not the driver specific implementation
)

driver.execute(1750187992, """INSERT INTO foo VALUES ($1, $2, $3, $4, $5, $6, $7, $8)""", 8) {
  check(this is PostgresPreparedStatement)
  bindUUID(7, uuid)
}

Idea:

interface SqlDriver<PrepareStatement: SqlPreparedStatement> {
 fun execute(
    identifier: Int?,
    sql: String,
    parameters: Int,
    binders: (PrepareStatement.() -> Unit)? = null,
  ): QueryResult<Long>
}

driver.execute(1750187992, """INSERT INTO foo VALUES ($1, $2, $3, $4, $5, $6, $7, $8)""", 8) {
  bindUUID(7, uuid)
}
@hfhbd hfhbd added the feature label Dec 4, 2022
@sqldelight sqldelight deleted a comment from Camille0183 Dec 23, 2022
@sqldelight sqldelight deleted a comment from Camille0183 Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant