-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin implementing sqlalchemy loader SQLA load job, factory, schema storage, POC sqlalchemy tests attempt Implement SqlJobClient interface Parquet load, some tests running on mysql update lockfile Limit bulk insert chunk size, sqlite create/drop schema, fixes Generate schema update Get more tests running with mysql More tests passing Fix state, schema restore
- Loading branch information
Showing
25 changed files
with
1,244 additions
and
78 deletions.
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
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
Empty file.
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,58 @@ | ||
from typing import TYPE_CHECKING, Optional, Any, Final, Type, Dict | ||
import dataclasses | ||
|
||
from dlt.common.configuration import configspec | ||
from dlt.common.configuration.specs import ConnectionStringCredentials | ||
from dlt.common.destination.reference import DestinationClientDwhConfiguration | ||
|
||
if TYPE_CHECKING: | ||
from sqlalchemy.engine import Engine, Dialect | ||
|
||
|
||
@configspec | ||
class SqlalchemyCredentials(ConnectionStringCredentials): | ||
if TYPE_CHECKING: | ||
_engine: Optional["Engine"] = None | ||
|
||
username: Optional[str] = None # e.g. sqlite doesn't need username | ||
|
||
def parse_native_representation(self, native_value: Any) -> None: | ||
from sqlalchemy.engine import Engine | ||
|
||
if isinstance(native_value, Engine): | ||
self.engine = native_value | ||
super().parse_native_representation( | ||
native_value.url.render_as_string(hide_password=False) | ||
) | ||
else: | ||
super().parse_native_representation(native_value) | ||
|
||
@property | ||
def engine(self) -> Optional["Engine"]: | ||
return getattr(self, "_engine", None) # type: ignore[no-any-return] | ||
|
||
@engine.setter | ||
def engine(self, value: "Engine") -> None: | ||
self._engine = value | ||
|
||
def get_dialect(self) -> Optional[Type["Dialect"]]: | ||
if not self.drivername: | ||
return None | ||
# Type-ignore because of ported URL class has no get_dialect method, | ||
# but here sqlalchemy should be available | ||
if engine := self.engine: | ||
return type(engine.dialect) | ||
return self.to_url().get_dialect() # type: ignore[attr-defined,no-any-return] | ||
|
||
|
||
@configspec | ||
class SqlalchemyClientConfiguration(DestinationClientDwhConfiguration): | ||
destination_type: Final[str] = dataclasses.field(default="sqlalchemy", init=False, repr=False, compare=False) # type: ignore | ||
credentials: SqlalchemyCredentials = None | ||
"""SQLAlchemy connection string""" | ||
|
||
engine_args: Dict[str, Any] = dataclasses.field(default_factory=dict) | ||
"""Additional arguments passed to `sqlalchemy.create_engine`""" | ||
|
||
def get_dialect(self) -> Type["Dialect"]: | ||
return self.credentials.get_dialect() |
Oops, something went wrong.