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

hides sql alchemy generics #385

Merged
merged 1 commit into from
Feb 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions sources/sql_database/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from typing import (
Callable,
cast,
Any,
List,
Optional,
Iterator,
Dict,
Union,
)
import operator
Expand All @@ -16,12 +14,11 @@
from dlt.sources.credentials import ConnectionStringCredentials
from dlt.common.configuration.specs import BaseConfiguration, configspec
from dlt.common.typing import TDataItem
from .schema_types import table_to_columns

from .schema_types import table_to_columns, Table, SelectAny

from sqlalchemy import Table, create_engine
from sqlalchemy.engine import Engine
from sqlalchemy.sql import Select
from sqlalchemy import Table


class TableLoader:
Expand All @@ -48,7 +45,7 @@ def __init__(
self.cursor_column = None
self.last_value = None

def make_query(self) -> Select[Any]:
def make_query(self) -> SelectAny:
table = self.table
query = table.select()
if not self.incremental:
Expand Down
16 changes: 12 additions & 4 deletions sources/sql_database/schema_types.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from typing import Any, Optional

from typing import Optional, Any, Type, TYPE_CHECKING
from typing_extensions import TypeAlias
from sqlalchemy import Table, Column, Select
from sqlalchemy.sql import sqltypes
from sqlalchemy import Table, Column

from dlt.common.schema.typing import TColumnSchema, TTableSchemaColumns

# optionally create generics with any so they can be imported by dlt importer
if TYPE_CHECKING:
SelectAny: TypeAlias = Select[Any]
ColumnAny: TypeAlias = Column[Any]
else:
SelectAny: TypeAlias = Type[Any]
ColumnAny: TypeAlias = Type[Any]


def sqla_col_to_column_schema(sql_col: Column[Any]) -> Optional[TColumnSchema]:
def sqla_col_to_column_schema(sql_col: ColumnAny) -> Optional[TColumnSchema]:
"""Infer dlt schema column type from an sqlalchemy type.

Precision and scale is inferred from that types that support it,
Expand Down
Loading