-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Integrate API * Add isort into linter list
- Loading branch information
1 parent
e649fec
commit 5fe82bc
Showing
22 changed files
with
233 additions
and
341 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from app.model import QueryDTO | ||
from app.model.data_source import DataSource | ||
|
||
|
||
# Rebuild model to validate the dto is correct via validation of the pydantic | ||
def verify_query_dto(data_source: DataSource, dto: QueryDTO): | ||
data_source.get_dto_type()(**dto.model_dump(by_alias=True)) |
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,91 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Union | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
manifest_str_field = Field(alias="manifestStr", description="Base64 manifest") | ||
connection_info_field = Field(alias="connectionInfo") | ||
|
||
|
||
class QueryDTO(BaseModel): | ||
sql: str | ||
manifest_str: str = manifest_str_field | ||
column_dtypes: dict[str, str] | None = Field( | ||
alias="columnDtypes", | ||
description="If this field is set, it will forcibly convert the type.", | ||
default=None, | ||
) | ||
connection_info: ConnectionInfo = connection_info_field | ||
|
||
|
||
class QueryBigQueryDTO(QueryDTO): | ||
connection_info: BigQueryConnectionInfo = connection_info_field | ||
|
||
|
||
class QueryMySqlDTO(QueryDTO): | ||
connection_info: ConnectionUrl | MySqlConnectionInfo = connection_info_field | ||
|
||
|
||
class QueryPostgresDTO(QueryDTO): | ||
connection_info: ConnectionUrl | PostgresConnectionInfo = connection_info_field | ||
|
||
|
||
class QuerySnowflakeDTO(QueryDTO): | ||
connection_info: SnowflakeConnectionInfo = connection_info_field | ||
|
||
|
||
class BigQueryConnectionInfo(BaseModel): | ||
project_id: str | ||
dataset_id: str | ||
credentials: str = Field(description="Base64 encode `credentials.json`") | ||
|
||
|
||
class MySqlConnectionInfo(BaseModel): | ||
host: str | ||
port: int | ||
database: str | ||
user: str | ||
password: str | ||
|
||
|
||
class ConnectionUrl(BaseModel): | ||
connection_url: str = Field(alias="connectionUrl") | ||
|
||
|
||
class PostgresConnectionInfo(BaseModel): | ||
host: str = Field(examples=["localhost"]) | ||
port: int = Field(examples=[5432]) | ||
database: str | ||
user: str | ||
password: str | ||
|
||
|
||
class SnowflakeConnectionInfo(BaseModel): | ||
user: str | ||
password: str | ||
account: str | ||
database: str | ||
sf_schema: str = Field( | ||
alias="schema" | ||
) # Use `sf_schema` to avoid `schema` shadowing in BaseModel | ||
|
||
|
||
ConnectionInfo = Union[ | ||
BigQueryConnectionInfo, | ||
ConnectionUrl, | ||
MySqlConnectionInfo, | ||
PostgresConnectionInfo, | ||
SnowflakeConnectionInfo, | ||
] | ||
|
||
|
||
class ValidateDTO(BaseModel): | ||
manifest_str: str = manifest_str_field | ||
parameters: dict[str, str] | ||
connection_info: ConnectionInfo = connection_info_field | ||
|
||
|
||
class AnalyzeSQLDTO(BaseModel): | ||
manifest_str: str = manifest_str_field | ||
sql: str |
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
Oops, something went wrong.