Skip to content

Add SQL builder utilities for PostgreSQL replication management#64

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

Add SQL builder utilities for PostgreSQL replication management#64
isdaniel wants to merge 3 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
  • simplify SQL command construction in sql_builder.rs

- 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
- simplify SQL command construction in sql_builder.rs
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.40%. Comparing base (b738aef) to head (d82aef1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #64      +/-   ##
==========================================
+ Coverage   93.74%   94.40%   +0.65%     
==========================================
  Files          10       11       +1     
  Lines       14364    15251     +887     
==========================================
+ Hits        13466    14398     +932     
+ Misses        898      853      -45     

☔ 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 building logic into a new sql_builder module, replacing duplicated sanitization and quoting helpers across the libpq and native connection implementations. The refactoring improves safety by introducing null byte checks and standardizing identifier and literal quoting. Consequently, several methods that previously returned String have been updated to return Result<String> to accommodate potential configuration errors. Feedback was provided regarding the redefinition of a constant that is already available in the types module.

Comment thread src/sql_builder.rs Outdated
@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 introduces a centralized sql_builder module to handle the construction of PostgreSQL replication protocol commands. It refactors the libpq and native connection implementations to delegate SQL generation to this new module, replacing duplicated sanitization and quoting logic. The new implementation includes enhanced security checks, such as null byte validation for identifiers and literals, and provides a suite of unit tests for the builder functions. I have no feedback to provide.

@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 command construction for PostgreSQL replication by introducing a new sql_builder module. It refactors both the libpq and native connection implementations to utilize these shared utilities, replacing internal sanitization and quoting functions. The new implementation enhances security by explicitly checking for and rejecting null bytes in SQL identifiers and literals. Consequently, several internal SQL building methods now return a Result<String> instead of a plain String. I have no feedback to provide as there are no review comments.

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