Skip to content
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

clickhouse-dsn #9062

Merged
merged 2 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pydantic/__init__.py
Expand Up @@ -124,6 +124,7 @@
'NatsDsn',
'MySQLDsn',
'MariaDBDsn',
'ClickHouseDsn',
'validate_email',
# root_model
'RootModel',
Expand Down Expand Up @@ -277,6 +278,7 @@
'NatsDsn': (__package__, '.networks'),
'MySQLDsn': (__package__, '.networks'),
'MariaDBDsn': (__package__, '.networks'),
'ClickHouseDsn': (__package__, '.networks'),
'validate_email': (__package__, '.networks'),
# root_model
'RootModel': (__package__, '.root_model'),
Expand Down
15 changes: 15 additions & 0 deletions pydantic/networks.py
Expand Up @@ -45,6 +45,7 @@
'validate_email',
'MySQLDsn',
'MariaDBDsn',
'ClickHouseDsn',
]


Expand Down Expand Up @@ -354,6 +355,20 @@ def check_db_name(cls, v):
]
"""A type that will accept any MariaDB DSN.

* User info required
* TLD not required
* Host required
"""
ClickHouseDsn = Annotated[
Url,
UrlConstraints(
allowed_schemes=['clickhouse+native', 'clickhouse+asynch'],
default_host='localhost',
default_port=9000,
),
]
"""A type that will accept any ClickHouse DSN.

* User info required
* TLD not required
* Host required
Expand Down
15 changes: 15 additions & 0 deletions tests/test_networks.py
Expand Up @@ -9,6 +9,7 @@
AmqpDsn,
AnyUrl,
BaseModel,
ClickHouseDsn,
CockroachDsn,
FileUrl,
HttpUrl,
Expand Down Expand Up @@ -419,6 +420,20 @@ class Model(BaseModel):
assert str(Model(a=dsn).a) == dsn


@pytest.mark.parametrize(
'dsn',
[
'clickhouse+native://user:pass@localhost:9000/app',
'clickhouse+asynch://user:pass@localhost:9000/app',
],
)
def test_clickhouse_dsns(dsn):
class Model(BaseModel):
a: ClickHouseDsn

assert str(Model(a=dsn).a) == dsn


@pytest.mark.parametrize(
'dsn,error_message',
(
Expand Down