generated from ydataai/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for schema in connectors and datasources (#86)
- Loading branch information
Showing
13 changed files
with
163 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Alias generators for converting between different capitalization conventions.""" | ||
import re | ||
|
||
__all__ = ('to_pascal', 'to_camel') | ||
|
||
|
||
def to_pascal(snake: str) -> str: | ||
"""Convert a snake_case string to PascalCase. | ||
Args: | ||
snake: The string to convert. | ||
Returns: | ||
The PascalCase string. | ||
""" | ||
camel = snake.title() | ||
return re.sub('([0-9A-Za-z])_(?=[0-9A-Z])', lambda m: m.group(1), camel) | ||
|
||
|
||
def to_camel(snake: str) -> str: | ||
"""Convert a snake_case string to camelCase. | ||
Args: | ||
snake: The string to convert. | ||
Returns: | ||
The converted camelCase string. | ||
""" | ||
camel = to_pascal(snake) | ||
return re.sub('(^_*[A-Z])', lambda m: m.group(1).lower(), camel) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import Optional | ||
|
||
from pydantic import Field | ||
|
||
from ydata.sdk.connectors._models.schema import Schema | ||
|
||
from .connector import Connector | ||
|
||
|
||
class RDBMSConnector(Connector): | ||
db_schema: Optional[Schema] = Field(None, alias="schema") |
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,43 @@ | ||
from typing import List, Optional | ||
|
||
from pydantic import Field | ||
|
||
from ydata.sdk.common.model import BaseModel | ||
from ydata.sdk.common.pydantic_utils import to_camel | ||
|
||
|
||
class BaseConfig(BaseModel.Config): | ||
alias_generator = to_camel | ||
|
||
|
||
class TableColumn(BaseModel): | ||
"""Class to store the information of a Column table.""" | ||
|
||
name: str | ||
variable_type: str # change this to the datatypes | ||
primary_key: Optional[bool] | ||
is_foreign_key: Optional[bool] | ||
foreign_keys: list | ||
nullable: bool | ||
|
||
Config = BaseConfig | ||
|
||
|
||
class Table(BaseModel): | ||
"""Class to store the table columns information.""" | ||
|
||
name: str | ||
columns: List[TableColumn] | ||
primary_keys: List[TableColumn] | ||
foreign_keys: List[TableColumn] | ||
|
||
Config = BaseConfig | ||
|
||
|
||
class Schema(BaseModel): | ||
"""Class to store the database schema information.""" | ||
|
||
name: str | ||
tables: Optional[List[Table]] = Field(None) | ||
|
||
Config = BaseConfig |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
from pydantic import BaseModel | ||
|
||
from ydata.sdk.common.model import BaseModel | ||
from ydata.sdk.datasources._models.metadata.warning_types import Level, WarningType | ||
|
||
|
||
class Details(BaseModel): | ||
level: Level | ||
value: str | ||
|
||
class Config: | ||
use_enum_values = True | ||
|
||
|
||
class MetadataWarning(BaseModel): | ||
column: str | ||
details: Details | ||
type: WarningType | ||
|
||
class Config: | ||
use_enum_values = 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
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