Skip to content

Add SQL builder utilities for PostgreSQL replication management#63

Closed
isdaniel wants to merge 4 commits intomainfrom
chore/sql-builder-improve
Closed

Add SQL builder utilities for PostgreSQL replication management#63
isdaniel wants to merge 4 commits intomainfrom
chore/sql-builder-improve

Conversation

@isdaniel
Copy link
Copy Markdown
Owner

@isdaniel isdaniel commented May 4, 2026

  • Introduced a new module sql_builder containing functions for building SQL statements related to replication slots and subscriptions.
  • Implemented quoting functions for identifiers and string literals to prevent SQL injection.
  • Added SQL builders for creating, altering, dropping, and managing replication slots and subscriptions.
  • Included tests for all new functionalities to ensure correctness and prevent regressions.
  • update SQL generation for START_REPLICATION to remove unnecessary parentheses and add null byte checks in quoting functions

- Introduced a new module `sql_builder` containing functions for building SQL statements related to replication slots and subscriptions.
- Implemented quoting functions for identifiers and string literals to prevent SQL injection.
- Added SQL builders for creating, altering, dropping, and managing replication slots and subscriptions.
- Included tests for all new functionalities to ensure correctness and prevent regressions.
- update SQL generation for START_REPLICATION to remove unnecessary parentheses and add null byte checks in quoting functions
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 99.51784% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.09%. Comparing base (b738aef) to head (9fbf3b2).

Files with missing lines Patch % Lines
src/connection/libpq.rs 92.64% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
+ Coverage   93.74%   94.09%   +0.34%     
==========================================
  Files          10       11       +1     
  Lines       14364    15200     +836     
==========================================
+ Hits        13466    14302     +836     
  Misses        898      898              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes SQL construction logic into a new sql_builder module, removing duplicated sanitization and quoting utilities from the libpq and native connection implementations. The new module provides structured builders for replication slot management, subscription management, and base backup commands, along with comprehensive unit tests. Feedback focuses on improving the idiomaticity of the new code by replacing manual string buffer management and loops with more concise format! calls and iterator patterns.

Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs Outdated
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes SQL building logic for PostgreSQL replication commands into a new sql_builder module, replacing duplicated inline string formatting in both libpq and native connection implementations. The new module provides robust quoting utilities for identifiers and literals, including safety checks against null bytes. Additionally, the generated SQL for replication commands has been refined to omit empty parentheses when no options are provided. I have no feedback to provide.

style: format SQL statement in build_detach_slot_sql for improved readability
@isdaniel
Copy link
Copy Markdown
Owner Author

isdaniel commented May 4, 2026

/gemini review

@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini is experiencing higher than usual traffic and was unable to create the review. Please try again in a few hours by commenting /gemini review.

@isdaniel
Copy link
Copy Markdown
Owner Author

isdaniel commented May 4, 2026

/gemini review.

@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini is experiencing higher than usual traffic and was unable to create the review. Please try again in a few hours by commenting /gemini review.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes SQL command construction into a new sql_builder module, removing duplicated logic from the libpq and native connection modules. The new module provides safe quoting and structured builders for replication and subscription management. Feedback focuses on improving the robustness of quoting functions by returning a Result instead of panicking on null bytes, and refactoring the physical replication SQL builder to use a vector-based join for better readability.

Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes SQL building logic for PostgreSQL replication commands into a new sql_builder module, removing duplicated sanitization and quoting helpers from the libpq and native connection implementations. This refactoring improves code reuse and ensures consistent SQL generation across the library. Feedback suggests importing the INVALID_XLOG_REC_PTR constant from crate::types rather than redefining it locally in the new module to maintain a single source of truth.

Comment thread src/sql_builder.rs
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes SQL building logic for PostgreSQL replication commands into a new sql_builder module, replacing duplicated logic in both libpq and native connection implementations. Feedback suggests optimizing string allocations in quoting functions by pre-calculating exact capacities and using std::fmt::Write for more maintainable string construction in physical replication SQL building.

Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs Outdated
Comment thread src/sql_builder.rs
- Updated SQL builder functions to return Result<String> instead of String, allowing for better error propagation.
- Modified the NativeConnection methods to handle the Result type from SQL builder functions.
- Adjusted tests to unwrap results from SQL builder functions, ensuring they handle potential errors.
- Added tests to verify that null byte inputs are correctly rejected across various SQL builder functions.
@isdaniel
Copy link
Copy Markdown
Owner Author

isdaniel commented May 4, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes SQL building logic into a new sql_builder module, refactoring both the libpq and native connection implementations to use these shared utilities. The changes include the introduction of robust quoting for identifiers and literals with security checks against null bytes, alongside specialized builders for replication and subscription management commands. All provided review comments were filtered out as they were purely validating the implementation rather than identifying issues or improvement opportunities, so I have no further feedback to provide.

@isdaniel isdaniel closed this May 4, 2026
@isdaniel isdaniel deleted the chore/sql-builder-improve branch May 4, 2026 09:56
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.

1 participant