Add SQL builder utilities for PostgreSQL replication management#63
Add SQL builder utilities for PostgreSQL replication management#63
Conversation
- 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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
/gemini review |
|
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. |
|
Warning Gemini is experiencing higher than usual traffic and was unable to create the review. Please try again in a few hours by commenting |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- 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.
|
/gemini review |
…plication SQL functions
There was a problem hiding this comment.
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.
sql_buildercontaining functions for building SQL statements related to replication slots and subscriptions.