Fix FormatDSN missing ConnectionAttributes
Description
Took into account ConnectionAttributes config, if set, in FormatDSN
Fixes https://github.com/go-sql-driver/mysql/issues/1618
Checklist
- [x] Code compiles correctly
- [x] Created tests which fail without the change (if possible)
- [x] All tests passing
- [ ] Extended the README / documentation, if necessary
- [x] Added myself / the copyright holder to the AUTHORS file
Summary by CodeRabbit
-
New Features
- Added support for including connection attributes in the generated DSN string, enhancing database configuration options.
- Expanded test coverage for database connection strings, focusing on handling various scenarios including unescaped values.
-
Documentation
- Updated the
AUTHORSfile to acknowledge Bogdan Constantinescu as a contributor.
- Updated the
Walkthrough
A new entry has been added to the AUTHORS file for Bogdan Constantinescu, positioned alphabetically among existing authors. Additionally, the FormatDSN method in the dsn.go file has been modified to include user-defined ConnectionAttributes in the generated DSN string. Correspondingly, the dsn_test.go file has been updated with new test cases for both valid and invalid DSN scenarios to ensure comprehensive testing of the DSN parser's functionality.
Changes
| Files | Change Summary |
|---|---|
AUTHORS |
Added Bogdan Constantinescu as a contributor. |
dsn.go, dsn_test.go |
Enhanced FormatDSN to include ConnectionAttributes. Added new test cases for valid and invalid DSNs to improve test coverage. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant Config
participant DSNBuilder
User->>Config: Create DSN with ConnectionAttributes
Config->>DSNBuilder: FormatDSN()
alt ConnectionAttributes present
DSNBuilder->>DSNBuilder: Append connectionAttributes to DSN
end
DSNBuilder->>User: Return formatted DSN
Possibly related PRs
- go-sql-driver/mysql#1667: Related to the addition of a new author in the
AUTHORSfile, similar to the changes made in this PR.
🐰 In fields of code, where logic hops wide,
New attributes dance, with data as guide.
Contributors join, a new name to cheer,
Together we build, with each line sincere!
💻✨
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 32a54ed153ba8779f6b03ba700e61ea6c3b0e6fd and 92fe4418d2f7541b8df3ea5b0ce8f21173829bef.
📒 Files selected for processing (3)
-
AUTHORS(1 hunks) -
dsn.go(1 hunks) -
dsn_test.go(2 hunks)
🔇 Additional comments (4)
AUTHORS (1)
27-27: Author entry added correctlyThe new author entry is positioned correctly in alphabetical order as per the file guidelines.
dsn.go (1)
310-312: Implementation correctly handles ConnectionAttributes in FormatDSNThis change properly addresses the issue mentioned in #1618 by including the ConnectionAttributes in the generated DSN when it's set. The value is correctly URL-escaped to ensure it's properly formatted for inclusion in the DSN string.
dsn_test.go (2)
81-82: Test case added for ConnectionAttributes in DSNGood addition of a test case that verifies the ConnectionAttributes are correctly included in the DSN and properly parsed. The test includes complex attributes with URL-escaped characters to ensure thorough testing.
116-116: Invalid DSN test case for unescaped ConnectionAttributesGood addition of an invalid test case that verifies the DSN parser correctly rejects unescaped values in ConnectionAttributes.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and generate unit testing code. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.