-
Notifications
You must be signed in to change notification settings - Fork 55
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
Do not require SQL URIs to be prefixed with SQLAlchemy driver #810
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
48a655e
Automatically set SQL driver if unset.
danielballan bfd540f
Handle special SQLite URIs
danielballan 02e702c
Consistently use database URI with schema.
danielballan 54c07f2
Interpret filepaths as SQLite URIs.
danielballan c70eed2
Parse uri earlier.
danielballan fe28a8a
Update CHANGELOG
danielballan 0b1181a
Fix missing arg in refactor.
danielballan 2aed6f4
Make utility accept Path-like objects.
danielballan 639cc26
Deal with Windows paths in test case
danielballan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from pathlib import Path | ||
|
||
from ..utils import ensure_specified_sql_driver | ||
|
||
|
||
def test_ensure_specified_sql_driver(): | ||
# Postgres | ||
# Default driver is added if missing. | ||
assert ( | ||
ensure_specified_sql_driver( | ||
"postgresql://user:password@localhost:5432/database" | ||
) | ||
== "postgresql+asyncpg://user:password@localhost:5432/database" | ||
) | ||
# Default driver passes through if specified. | ||
assert ( | ||
ensure_specified_sql_driver( | ||
"postgresql+asyncpg://user:password@localhost:5432/database" | ||
) | ||
== "postgresql+asyncpg://user:password@localhost:5432/database" | ||
) | ||
# Do not override user-provided. | ||
assert ( | ||
ensure_specified_sql_driver( | ||
"postgresql+custom://user:password@localhost:5432/database" | ||
) | ||
== "postgresql+custom://user:password@localhost:5432/database" | ||
) | ||
|
||
# SQLite | ||
# Default driver is added if missing. | ||
assert ( | ||
ensure_specified_sql_driver("sqlite:////test.db") | ||
== "sqlite+aiosqlite:////test.db" | ||
) | ||
# Default driver passes through if specified. | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+aiosqlite:////test.db") | ||
== "sqlite+aiosqlite:////test.db" | ||
) | ||
# Do not override user-provided. | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+custom:////test.db") | ||
== "sqlite+custom:////test.db" | ||
) | ||
# Handle SQLite :memory: URIs | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+aiosqlite://:memory:") | ||
== "sqlite+aiosqlite://:memory:" | ||
) | ||
assert ( | ||
ensure_specified_sql_driver("sqlite://:memory:") | ||
== "sqlite+aiosqlite://:memory:" | ||
) | ||
# Handle SQLite relative URIs | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+aiosqlite:///test.db") | ||
== "sqlite+aiosqlite:///test.db" | ||
) | ||
assert ( | ||
ensure_specified_sql_driver("sqlite:///test.db") | ||
== "sqlite+aiosqlite:///test.db" | ||
) | ||
# Filepaths are implicitly SQLite databases. | ||
# Relative path | ||
assert ensure_specified_sql_driver("test.db") == "sqlite+aiosqlite:///test.db" | ||
# Path object | ||
assert ensure_specified_sql_driver(Path("test.db")) == "sqlite+aiosqlite:///test.db" | ||
# Relative path anchored to . | ||
assert ensure_specified_sql_driver("./test.db") == "sqlite+aiosqlite:///test.db" | ||
# Absolute path | ||
assert ( | ||
ensure_specified_sql_driver(Path("/tmp/test.db")) | ||
== f"sqlite+aiosqlite:///{Path('/tmp/test.db')}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Did you not use
urllib
to parse because in theory this could be URI that's not a URL?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.
I remember reaching for
urllib
first. I believe the issue was that certain SQLite URIs do not round-trip quite right.