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

Complete Type Mapping #64

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bd1ac79
Type Mapping #1
rayliverified Sep 18, 2024
a50c336
Type Mapping #2
rayliverified Sep 18, 2024
655b05c
Reformat Files
rayliverified Sep 23, 2024
cd5025d
Fix Datetime Import
rayliverified Sep 23, 2024
5435d2f
Fix Default DateTime Types
rayliverified Sep 23, 2024
170052c
Lowercase Types for Consistency
rayliverified Sep 23, 2024
d5aa435
Fix Varchar Collation Type
rayliverified Sep 23, 2024
1971fec
Disable Flake8 Complexity Rule
rayliverified Sep 23, 2024
0e56cc4
Remove Int and Text Extra Column Properties
rayliverified Sep 23, 2024
7adaefa
Create Field Aliases
rayliverified Sep 23, 2024
bbe4c5b
Create Field Aliases #2
rayliverified Sep 23, 2024
cb01490
Create Field Aliases #3
rayliverified Sep 23, 2024
b78ce45
Add User Customizable Type Mapping
rayliverified Sep 23, 2024
557a991
Remove Unnecessary Lowercase
rayliverified Sep 23, 2024
1029e20
Generate Boolean Defaults
rayliverified Sep 24, 2024
a357502
Handle GENERATED ALWAYS AS
rayliverified Sep 26, 2024
57974b3
QUICKFIX Type Mapping Import
rayliverified Sep 27, 2024
6a93099
Table Prefix and Suffix Support
rayliverified Sep 27, 2024
b354a0f
Table Prefix and Suffix Support #2
rayliverified Sep 27, 2024
455501c
Update simple-ddl-parser
rayliverified Sep 30, 2024
040f6a2
Create Date and Time Types
rayliverified Oct 1, 2024
e543322
Create Date and Time Types #2
rayliverified Oct 1, 2024
f9d4aa5
Create Date and Time Types #3
rayliverified Oct 1, 2024
052bc40
Fix Annotations
rayliverified Oct 1, 2024
857e151
Merge branch 'main' into ray-type-mapping
rayliverified Oct 1, 2024
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
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[flake8]
exclude = .github,.git,__pycache__,docs/source/conf.py,old,build,dist,models.py,omymodels/test.py
ignore = D100, D103, D101, D102, D104,D107, D403, D210, D400, D401, W503, W293, D205
max-complexity = 10
max-line-length = 120
18 changes: 17 additions & 1 deletion omymodels/from_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def create_models(
defaults_off: Optional[bool] = False,
exit_silent: Optional[bool] = False,
no_auto_snake_case: Optional[bool] = False,
table_prefix: Optional[str] = "",
table_suffix: Optional[str] = "",
):
"""models_type can be: "gino", "dataclass", "pydantic" """
# extract data from ddl file
Expand All @@ -55,7 +57,14 @@ def create_models(
raise NoTablesError()
# generate code
output = generate_models_file(
data, singular, naming_exceptions, models_type, schema_global, defaults_off
data,
singular,
naming_exceptions,
models_type,
schema_global,
defaults_off,
table_prefix=table_prefix,
table_suffix=table_suffix,
)
if dump:
save_models_to_file(output, dump_path)
Expand Down Expand Up @@ -99,6 +108,9 @@ def convert_ddl_to_models( # noqa: C901
column["name"] = snake_case(column["name"])
if column["name"] in refs:
column["references"] = refs[column["name"]]
if "generated" in column:
column["generated_as"] = column["generated"]["as"]

if not no_auto_snake_case:
table["primary_key"] = [snake_case(pk) for pk in table["primary_key"]]
for uniq in table.get("constraints", {}).get("uniques", []):
Expand Down Expand Up @@ -133,6 +145,8 @@ def generate_models_file(
models_type: str = "gino",
schema_global: bool = True,
defaults_off: Optional[bool] = False,
table_prefix: Optional[str] = "",
table_suffix: Optional[str] = "",
) -> str:
"""method to prepare full file with all Models &"""
models_str = ""
Expand All @@ -152,6 +166,8 @@ def generate_models_file(
exceptions,
schema_global=schema_global,
defaults_off=defaults_off,
table_prefix=table_prefix,
table_suffix=table_suffix,
)
header += generator.create_header(
data["tables"], schema=schema_global, models_str=models_str
Expand Down
17 changes: 14 additions & 3 deletions omymodels/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ def add_custom_types_to_generator(types: List[Type], generator: object) -> objec


def datetime_now_check(string: str) -> bool:
if "now" in string or "current_timestamp" in string:
return True
return False
now_keywords = [
"now",
"current_timestamp",
"current_date",
"current_time",
"localtime",
"localtimestamp",
"sysdate",
"getdate",
"current",
"curdate",
"curtime",
]
return any(keyword in string.lower() for keyword in now_keywords)
6 changes: 4 additions & 2 deletions omymodels/logic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Dict, List

from table_meta.model import Column

import omymodels.types as t


def generate_column(
column_data: Dict,
column_data: Column,
table_pk: List[str],
table_data: Dict,
schema_global: bool,
Expand All @@ -24,7 +26,7 @@ def generate_column(


def setup_column_attributes(
column_data: Dict,
column_data: Column,
table_pk: List[str],
column: str,
table_data: Dict,
Expand Down
Loading
Loading