Conversation
| @staticmethod | ||
| def ddl() -> str: | ||
| def ddl(len: int = 0) -> str: | ||
| return 'ARRAY<STRING(MAX)>' |
There was a problem hiding this comment.
this should respect string length.
| @staticmethod | ||
| def ddl() -> str: | ||
| def ddl(len: int = 0) -> str: | ||
| return 'BYTES(MAX)' |
There was a problem hiding this comment.
this should respect string length
spanner_orm/admin/column.py
Outdated
| for field_type in field.ALL_TYPES: | ||
| if self.spanner_type == field_type.ddl(): | ||
| len = _get_str_len(self.spanner_type) | ||
| if self.spanner_type == field_type.ddl(len): |
There was a problem hiding this comment.
Instead, leave field_type.ddl() to always return string with (MAX). And then you just replace (len) with (MAX) in the spanner_type and compare that. You can add a property supports_length which returns bool when this substitution is needed, to avoid replacing MAX in all possible types.
There was a problem hiding this comment.
Done.
I didn't add property. Instead, I added a check in the init function. If the type is not length_support, the length is always 0 and we skip the string replacement.
spanner_orm/field.py
Outdated
| if self._nullable: | ||
| return self._type.ddl() | ||
| return '{field_type} NOT NULL'.format(field_type=self._type.ddl()) | ||
| return self._type.ddl(self._length) |
There was a problem hiding this comment.
Maybe a bit cleaner would be to let _type.ddl() to return MAX and then if the length is defined, do str replace for (MAX) to (len). This way you don't have to pass the length to static ddl method in all classes.
You can also add a property called supports_length to the field type, and check it - if its false and len is non zero - throw an exception.
No description provided.