Skip to content

Commit

Permalink
feat: add list 1d string column (#111)
Browse files Browse the repository at this point in the history
add list 1d string column
  • Loading branch information
rzlim08 authored Oct 10, 2024
1 parent 667ce35 commit 8b9b9a5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class {{cls.name}}(Entity):
{%- elif attr.type == "string" %}
{{attr.name}}: Mapped[str] = mapped_column(String, nullable={{ "False" if attr.required else "True"}}{%- if attr.indexed%}, index=True{%- endif %})
{%- elif attr.type == "Array2dFloat" %}
{{attr.name}}: Mapped[JSONB] = mapped_column(JSONB, nullable={{ "False" if attr.required else "True"}})
{%- elif attr.type == "List1dString" %}
{{attr.name}}: Mapped[JSONB] = mapped_column(JSONB, nullable={{ "False" if attr.required else "True"}})
{%- elif attr.type == "integer" %}
{{attr.name}}: Mapped[int] = mapped_column(Integer, nullable={{ "False" if attr.required else "True"}}{%- if attr.indexed%}, index=True{%- endif %})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class {{ cls.name }}GroupByOptions:
{{ attr.name }}: Optional[uuid.UUID] = None
{%- elif attr.type == "Array2dFloat" %}
{{ attr.name }}: Optional[list[list[float]]] = None
{%- elif attr.type == "List1dString" %}
{{ attr.name }}: Optional[list[str]] = None
{%- else %}
{{ attr.name }}: Optional[{{ attr.type }}] = None
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class {{ cls.name }}(EntityInterface):
{{ attr.name }}: {{ getType("str", attr.required) }}
{%- elif attr.type == "Array2dFloat" %}
{{ attr.name }}: {{ getType("List[List[float]]", attr.required) }}
{%- elif attr.type == "List1dString" %}
{{ attr.name }}: {{ getType("List[str]", attr.required) }}
{%- elif attr.is_enum %}
{{ attr.name }}: {{ getType(attr.type, attr.required) }}
{%- elif attr.type == "integer" %}
Expand Down Expand Up @@ -373,6 +375,8 @@ Mutation types
{{ attr.name }}: {{ getTypeMutation(action, "strawberry.ID", attr.required) }}
{%- elif attr.type == "Array2dFloat" %}
{{ attr.name }}: {{ getTypeMutation(action, "List[List[float]]", attr.required) }}
{%- elif attr.type == "List1dString" %}
{{ attr.name }}: {{ getTypeMutation(action, "List[str]", attr.required) }}
{%- elif attr.is_enum %}
{{ attr.name }}: {{ getTypeMutation(action, attr.type, attr.required) }}
{%- elif attr.type == "integer" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class {{ cls.name }}Factory(CommonFactory):
{{ field.name }} = fuzzy.FuzzyText()
{%- elif field.type == "Array2dFloat" %}
{{ field.name }} = factory.LazyAttribute(lambda o: [ [random.uniform(1, 100) for _ in range(5)] ] * random.randint(2, 5) )
{%- elif field.type == "List1dString" %}
{{ field.name }} = factory.LazyAttribute(lambda o: [ factory.Faker("word").generate() for _ in range(random.randint(2, 5)) ])
{%- elif field.type == "integer" %}
{{ field.name }} = fuzzy.FuzzyInteger(1, 1000)
{%- elif field.type == "float" %}
Expand Down
2 changes: 2 additions & 0 deletions platformics/codegen/templates/validators/class_name.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ from typing_extensions import Annotated
{{ attr.name }}: Annotated[{{ getTypeValidation(action, "float", attr.required) }}, Field({{getNumericConstraints(attr)}})]
{%- elif attr.type == "Array2dFloat" %}
{{ attr.name }}: Annotated[{{ getTypeValidation(action, "list[list[float]]", attr.required) }}, Field()]
{%- elif attr.type == "List1dString" %}
{{ attr.name }}: Annotated[{{ getTypeValidation(action, "list[str]", attr.required) }}, Field()]
{%- elif attr.is_enum %}
{{ attr.name }}: Annotated[{{ getTypeValidation(action, attr.type, attr.required) }}, Field()]
{%- elif attr.type == "boolean" %}
Expand Down

0 comments on commit 8b9b9a5

Please sign in to comment.