Skip to content

Commit

Permalink
Fixed date and date-time types convert rules (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
svdimchenko authored May 7, 2024
1 parent 43219e9 commit b455b02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pydantic_glue/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def dispatch(v: dict[str, Any]) -> str:
return handle_array(v)

if t == "string":
if v.get("format") == "date-time":
return "timestamp"
if v.get("format") == "date":
return "date"
return "string"

if t == "boolean":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "pydantic-glue"
keywords = ["pydantic", "glue", "athena", "types", "convert"]
version = "0.2.1"
version = "0.3.0"
description = "Convert pydantic model to aws glue schema for terraform"
authors = ["Serhii Dimchenko <[email protected]>"]
readme = "README.md"
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import json
from typing import Optional, Union

Expand Down Expand Up @@ -33,6 +34,22 @@ class A(BaseModel):
assert convert(json.dumps(A.model_json_schema())) == expected


def test_single_date_column():
class A(BaseModel):
modifiedOn: datetime.date

expected = [("modifiedOn", "date")]
assert convert(json.dumps(A.model_json_schema())) == expected


def test_single_datetime_column():
class A(BaseModel):
modifiedOn: datetime.datetime

expected = [("modifiedOn", "timestamp")]
assert convert(json.dumps(A.model_json_schema())) == expected


def test_multiple_string_column():
class A(BaseModel):
hey: str
Expand Down

0 comments on commit b455b02

Please sign in to comment.