Skip to content

Commit

Permalink
rename Connection -> ConnectionUrl
Browse files Browse the repository at this point in the history
Signed-off-by: ZhengYu, Xu <zen-xu@outlook.com>
  • Loading branch information
zen-xu committed Apr 21, 2024
1 parent f21da09 commit 349d742
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
42 changes: 21 additions & 21 deletions connectorx-python/connectorx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@


def rewrite_conn(
conn: str | Connection, protocol: Protocol | None = None
conn: str | ConnectionUrl, protocol: Protocol | None = None
) -> tuple[str, Protocol]:
if not protocol:
# note: redshift/clickhouse are not compatible with the 'binary' protocol, and use other database
Expand All @@ -66,7 +66,7 @@ def rewrite_conn(


def get_meta(
conn: str | Connection,
conn: str | ConnectionUrl,
query: str,
protocol: Protocol | None = None,
) -> pd.DataFrame:
Expand All @@ -91,7 +91,7 @@ def get_meta(


def partition_sql(
conn: str | Connection,
conn: str | ConnectionUrl,
query: str,
partition_on: str,
partition_num: int,
Expand Down Expand Up @@ -125,7 +125,7 @@ def partition_sql(

def read_sql_pandas(
sql: list[str] | str,
con: str | Connection | dict[str, str] | dict[str, Connection],
con: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
index_col: str | None = None,
protocol: Protocol | None = None,
partition_on: str | None = None,
Expand Down Expand Up @@ -166,7 +166,7 @@ def read_sql_pandas(
# default return pd.DataFrame
@overload
def read_sql(
conn: str | Connection | dict[str, str] | dict[str, Connection],
conn: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
query: list[str] | str,
*,
protocol: Protocol | None = None,
Expand All @@ -179,7 +179,7 @@ def read_sql(

@overload
def read_sql(
conn: str | Connection | dict[str, str] | dict[str, Connection],
conn: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
query: list[str] | str,
*,
return_type: Literal["pandas"],
Expand All @@ -193,7 +193,7 @@ def read_sql(

@overload
def read_sql(
conn: str | Connection | dict[str, str] | dict[str, Connection],
conn: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
query: list[str] | str,
*,
return_type: Literal["arrow", "arrow2"],
Expand All @@ -207,7 +207,7 @@ def read_sql(

@overload
def read_sql(
conn: str | Connection | dict[str, str] | dict[str, Connection],
conn: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
query: list[str] | str,
*,
return_type: Literal["modin"],
Expand All @@ -221,7 +221,7 @@ def read_sql(

@overload
def read_sql(
conn: str | Connection | dict[str, str] | dict[str, Connection],
conn: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
query: list[str] | str,
*,
return_type: Literal["dask"],
Expand All @@ -235,7 +235,7 @@ def read_sql(

@overload
def read_sql(
conn: str | Connection | dict[str, str] | dict[str, Connection],
conn: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
query: list[str] | str,
*,
return_type: Literal["polars", "polars2"],
Expand All @@ -248,7 +248,7 @@ def read_sql(


def read_sql(
conn: str | Connection | dict[str, str] | dict[str, Connection],
conn: str | ConnectionUrl | dict[str, str] | dict[str, ConnectionUrl],
query: list[str] | str,
*,
return_type: Literal[
Expand Down Expand Up @@ -501,16 +501,16 @@ def try_import_module(name: str):
)


class Connection(Generic[_BackendT], str):
class ConnectionUrl(Generic[_BackendT], str):
@overload
def __new__(
cls,
*,
backend: Literal["sqlite"],
db_path: str | Path,
) -> Connection[Literal["sqlite"]]:
) -> ConnectionUrl[Literal["sqlite"]]:
"""
Help to build sqlite connection string.
Help to build sqlite connection string url.
Parameters
==========
Expand All @@ -526,9 +526,9 @@ def __new__(
*,
backend: Literal["bigquery"],
db_path: str | Path,
) -> Connection[Literal["bigquery"]]:
) -> ConnectionUrl[Literal["bigquery"]]:
"""
Help to build BigQuery connection string.
Help to build BigQuery connection string url.
Parameters
==========
Expand All @@ -549,9 +549,9 @@ def __new__(
port: int,
database: str = "",
database_options: dict[str, str] | None = None,
) -> Connection[_ServerBackendT]:
) -> ConnectionUrl[_ServerBackendT]:
"""
Help to build server-side backend database connection string.
Help to build server-side backend database connection string url.
Parameters
==========
Expand All @@ -575,9 +575,9 @@ def __new__(
def __new__(
cls,
raw_connection: str,
) -> Connection:
) -> ConnectionUrl:
"""
Build connection from raw connection string
Build connection from raw connection string url
Parameters
==========
Expand All @@ -597,7 +597,7 @@ def __new__(
database: str = "",
database_options: dict[str, str] | None = None,
db_path: str | Path = "",
) -> Connection:
) -> ConnectionUrl:
if raw_connection is not None:
return super().__new__(cls, raw_connection)

Expand Down
6 changes: 3 additions & 3 deletions connectorx-python/connectorx/tests/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pandas.testing import assert_frame_equal

from .. import read_sql, Connection
from .. import read_sql, ConnectionUrl


@pytest.fixture(scope="module") # type: ignore
Expand Down Expand Up @@ -310,5 +310,5 @@ def test_bigquery_types(bigquery_url: str) -> None:
not os.environ.get("BIGQUERY_URL"),
reason="Test bigquery only when `BIGQUERY_URL` is set",
)
def test_connection(bigquery_url: str) -> None:
test_bigquery_types(Connection(bigquery_url))
def test_connection_url(bigquery_url: str) -> None:
test_bigquery_types(ConnectionUrl(bigquery_url))
6 changes: 3 additions & 3 deletions connectorx-python/connectorx/tests/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pandas.testing import assert_frame_equal

from .. import read_sql, Connection
from .. import read_sql, ConnectionUrl


@pytest.fixture(scope="module") # type: ignore
Expand Down Expand Up @@ -87,5 +87,5 @@ def test_clickhouse_types(clickhouse_url: str) -> None:
not os.environ.get("CLICKHOUSE_URL"),
reason="Do not test Clickhouse unless `CLICKHOUSE_URL` is set",
)
def test_connection(clickhouse_url: str) -> None:
test_clickhouse_types(Connection(clickhouse_url))
def test_connection_url(clickhouse_url: str) -> None:
test_clickhouse_types(ConnectionUrl(clickhouse_url))
6 changes: 3 additions & 3 deletions connectorx-python/connectorx/tests/test_mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal
from connectorx import Connection
from connectorx import ConnectionUrl

from .. import read_sql

Expand Down Expand Up @@ -498,5 +498,5 @@ def test_mssql_offset(mssql_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_connection(mssql_url: str) -> None:
test_mssql_offset(Connection(mssql_url))
def test_connection_url(mssql_url: str) -> None:
test_mssql_offset(ConnectionUrl(mssql_url))
6 changes: 3 additions & 3 deletions connectorx-python/connectorx/tests/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pandas.testing import assert_frame_equal

from .. import read_sql, Connection
from .. import read_sql, ConnectionUrl


@pytest.fixture(scope="module") # type: ignore
Expand Down Expand Up @@ -470,5 +470,5 @@ def test_mysql_cte(mysql_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_connection(mysql_url: str) -> None:
test_mysql_cte(Connection(mysql_url))
def test_connection_url(mysql_url: str) -> None:
test_mysql_cte(ConnectionUrl(mysql_url))
6 changes: 3 additions & 3 deletions connectorx-python/connectorx/tests/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pandas.testing import assert_frame_equal

from .. import read_sql, Connection
from .. import read_sql, ConnectionUrl


@pytest.fixture(scope="module") # type: ignore
Expand Down Expand Up @@ -446,5 +446,5 @@ def test_oracle_round_function(oracle_url: str) -> None:
@pytest.mark.skipif(
not os.environ.get("ORACLE_URL"), reason="Test oracle only when `ORACLE_URL` is set"
)
def test_connection(oracle_url: str) -> None:
test_oracle_round_function(Connection(oracle_url))
def test_connection_url(oracle_url: str) -> None:
test_oracle_round_function(ConnectionUrl(oracle_url))
6 changes: 3 additions & 3 deletions connectorx-python/connectorx/tests/test_redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from pandas.testing import assert_frame_equal

from .. import read_sql, Connection
from .. import read_sql, ConnectionUrl


@pytest.fixture(scope="module") # type: ignore
Expand Down Expand Up @@ -140,5 +140,5 @@ def test_read_sql_on_utf8(redshift_url: str) -> None:
not os.environ.get("REDSHIFT_URL"),
reason="Do not test Redshift unless `REDSHIFT_URL` is set",
)
def test_connection(redshift_url: str) -> None:
test_read_sql_on_utf8(Connection(redshift_url))
def test_connection_url(redshift_url: str) -> None:
test_read_sql_on_utf8(ConnectionUrl(redshift_url))
6 changes: 3 additions & 3 deletions connectorx-python/connectorx/tests/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from pandas.testing import assert_frame_equal

from .. import read_sql, Connection
from .. import read_sql, ConnectionUrl


@pytest.fixture(scope="module") # type: ignore
Expand Down Expand Up @@ -392,5 +392,5 @@ def test_sqlite_cte(sqlite_db: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_connection(sqlite_db: str) -> None:
test_sqlite_cte(Connection(sqlite_db))
def test_connection_url(sqlite_db: str) -> None:
test_sqlite_cte(ConnectionUrl(sqlite_db))

0 comments on commit 349d742

Please sign in to comment.