-
Notifications
You must be signed in to change notification settings - Fork 7
Add DB_URL support #240
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
Add DB_URL support #240
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for a custom database connection URL (DB_URL) as an alternative to specifying individual connection parameters (host, port, user, etc.). When DB_URL is provided, individual connection parameters become optional and can fall back to default values.
Key changes:
- Added
db_urlfield across configuration structures (CLI args, dotenv, and config structs) - Modified connection parameter validation to allow defaults when
DB_URLis present - Updated credential string builders to prioritize
DB_URLwhen available
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/common/cli.rs | Added CLI argument for custom database URL |
| src/common/dotenv.rs | Added support for reading DB_URL from environment variables |
| src/common/config.rs | Modified configuration logic to make individual DB parameters optional when DB_URL is provided, and updated credential string builders |
| tests/sample/sample.queries.ts | Added TypeScript query type definitions (appears unrelated to DB_URL feature) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| db_host, | ||
| db_port, | ||
| db_user, |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Removing .to_owned() calls here changes the ownership semantics. Since these are now owned values instead of references, this is correct, but the surrounding code at lines 328-329 still uses .to_owned() creating inconsistency. Consider applying the same pattern to db_pass and db_name for consistency.
tests/sample/sample.queries.ts
Outdated
| export interface ISampleSelectQueryQuery { | ||
| params: SampleSelectQueryParams; | ||
| result: ISampleSelectQueryResult; | ||
| } |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The interface name ISampleSelectQueryQuery contains redundant 'Query' suffix. Consider renaming to ISampleSelectQuery for clarity.
61f306e to
7022f96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let db_host = match (db_url.is_some(), db_host_chain()) { | ||
| (true, Some(v)) => v, | ||
| (true, None) => String::new(), | ||
| (false, Some(v)) => v, | ||
| (false, None) => panic!( |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern (db_url.is_some(), db_host_chain()) is repeated three times for db_host, db_port, and db_user. Consider extracting this logic into a helper function to reduce code duplication and improve maintainability.
| (true, Some(v)) => v, | ||
| (true, None) => 0, | ||
| (false, Some(v)) => v, |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 0 as a default port when db_url is provided but db_port is not may cause issues if the port value is used elsewhere in the code for validation or logging. Consider using a more explicit sentinel value or documenting this behavior, as port 0 is typically reserved and may not be a valid database port.
| (true, Some(v)) => v, | |
| (true, None) => 0, | |
| (false, Some(v)) => v, | |
| (true, Some(v)) => Some(v), | |
| (true, None) => None, | |
| (false, Some(v)) => Some(v), |
7022f96 to
a729125
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let demo_dir = tempdir()?; | ||
| let demo_path = demo_dir.path(); | ||
| let sql_file_path = demo_path.join("test-query.sql"); | ||
| let sample_query_path = demo_path.join("test-query.queries.ts"); |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable sample_query_path is declared but never used in this test. Consider removing it to avoid confusion.
| let sample_query_path = demo_path.join("test-query.queries.ts"); |
| let demo_dir = tempdir()?; | ||
| let demo_path = demo_dir.path(); | ||
| let sql_file_path = demo_path.join("test-query.sql"); | ||
| let sample_query_path = demo_path.join("test-query.queries.ts"); |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable sample_query_path is declared but never used in this test. Consider removing it to avoid confusion.
| let sample_query_path = demo_path.join("test-query.queries.ts"); |
|
|
||
| let db_port = match (db_url.is_some(), db_port_chain()) { | ||
| (true, Some(v)) => v, | ||
| (true, None) => 0, |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting db_port to 0 when db_url is provided but no port chain value exists could cause issues if the DB_URL is malformed or missing. Consider validating that db_url is actually valid before allowing zero as a fallback value.
|
|
||
| let db_user = match (db_url.is_some(), db_user_chain()) { | ||
| (true, Some(v)) => v, | ||
| (true, None) => String::new(), |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting db_user to an empty string when db_url is provided but no user chain value exists could cause issues if the DB_URL is malformed or missing. Consider validating that db_url is actually valid before allowing empty fallback values.
No description provided.