Skip to content

initial commit for supporting custom string and intarray - #1

Open
hazyd wants to merge 6 commits into
mainfrom
su
Open

initial commit for supporting custom string and intarray#1
hazyd wants to merge 6 commits into
mainfrom
su

Conversation

@hazyd

@hazyd hazyd commented Sep 3, 2022

Copy link
Copy Markdown
Owner

No description provided.

Comment thread spanner_orm/admin/column.py Outdated
Comment thread spanner_orm/field.py
@staticmethod
def ddl() -> str:
def ddl(len: int = 0) -> str:
return 'ARRAY<STRING(MAX)>'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should respect string length.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread spanner_orm/field.py
@staticmethod
def ddl() -> str:
def ddl(len: int = 0) -> str:
return 'BYTES(MAX)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should respect string length

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread 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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants