Skip to content

Commit

Permalink
hides sql alchemy generics
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfix committed Feb 29, 2024
1 parent eddfd3a commit 48d55be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
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

0 comments on commit 48d55be

Please sign in to comment.