Skip to content

Added readOnly mode #1325

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

Merged
merged 4 commits into from
Jul 16, 2025
Merged

Added readOnly mode #1325

merged 4 commits into from
Jul 16, 2025

Conversation

zaleslaw
Copy link
Collaborator

Fixes #1308

zaleslaw added 2 commits July 15, 2025 18:26
…C connection handling

- Added `DbConnectionConfig` to manage JDBC connection parameters, including `readOnly` mode for safe, read-only operations.
- Refactored JDBC handling to use `withReadOnlyConnection` utility, ensuring connections are properly closed, rolled back, and safe from unintended writes.
- Updated related methods (`readSqlTable`, `readSqlQuery`, etc.) to utilize the new utility.
- Enhanced documentation with detailed examples and behavior clarifications for `DbConnectionConfig`.
- Added tests for `withReadOnlyConnection` to validate read-only mode and connection rollback behavior.
@zaleslaw zaleslaw requested review from Copilot and koperagen July 15, 2025 17:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Introduces a new read-only mode for managed JDBC connections and refactors DataFrame read methods to use it.

  • Add readOnly flag to DbConnectionConfig and implement withReadOnlyConnection helper for safe rollback semantics.
  • Refactor DataFrame.Companion JDBC read methods (readSqlTable, readSqlQuery, etc.) to use the new helper.
  • Add an H2 integration test for withReadOnlyConnection.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dataframe-jdbc/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/h2/h2Test.kt Add test for withReadOnlyConnection behavior, including auto-commit disabling and rollback.
dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/readJdbc.kt Introduce DbConnectionConfig.readOnly, withReadOnlyConnection, and update DataFrame read methods to use managed connections.
Comments suppressed due to low confidence (4)

dataframe-jdbc/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/h2/h2Test.kt:1160

  • Test name indicates it sets read-only mode; consider adding an assertion like conn.isReadOnly shouldBe true to verify the read-only flag is applied.
            conn.autoCommit shouldBe false

dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/readJdbc.kt:129

  • The docs claim that data-modifying queries are rejected when readOnly=false, but no enforcement logic is implemented. Consider either implementing a statement filter or updating the documentation to reflect the actual behavior.
 *                    but the library will still reject any queries that appear to modify data

dataframe-jdbc/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/h2/h2Test.kt:1155

  • Missing import for DbConnectionConfig in this test file, causing a compilation error. Add import org.jetbrains.kotlinx.dataframe.io.DbConnectionConfig.
        val config = DbConnectionConfig("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", readOnly = true)

dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/readJdbc.kt:221

  • [nitpick] The default read-only behavior documentation is duplicated across several methods. Consider extracting this common description into a shared section or referencing a central doc to reduce duplication.
 * ### Default Behavior:

@zaleslaw zaleslaw merged commit a81307f into master Jul 16, 2025
3 checks passed
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.

How about readOnly for sql query?
2 participants