JetBrains / JetBrains/Exposed

Is there any way to execute pure queries in auto-commit mode?

Open
#306 12 comments 8 reactions 0 assignees View on GitHub
enhancement performance
Dominant language
Kotlin
Stars
9.3k
Forks
798
Avg merge
4d 2h
Merged PRs (30d)
26

Description

Exposed is great!

But it seems any operation in Exposed must be called within a `transaction` block. Sometimes it might be unnecessary to to use a real native transaction because the operations in it are pure queries.

```kotlin
val jamesList = transaction {
Users.select { Users.firstName eq "James" }
}
```

I've read the source code in [TreadLocalTransactionManager.kt](https://github.com/JetBrains/Exposed/blob/master/src/main/kotlin/org/jetbrains/exposed/sql/transactions/ThreadLocalTransactionManager.kt) and found that the `autoCommit` property is set to false after connection established.

In my option, it's better to provide a `execAutoCommit` method(or any other name) to encapsulate pure query operations, so that we can run queries in auto-commit mode, which might be good to performance in some cases.

```kotlin
val jamesList = execAutoCommit {
Users.select { Users.firstName eq "James" }
}
```

Anyway, thanks for your contribution to this framework, I like it very much. Please consider adding this feature.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.