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

Accept Meta class inside entity models to override datastore.Client instance params #4

Merged
merged 2 commits into from Nov 2, 2021

Conversation

exageraldo
Copy link
Owner

from noseiquela_orm import (Entity, ParentKey, BooleanField, FloatField,
                 IntegerField, StringField, ListField, DictField,
                 DateTimeField)

class Customer(Entity):
    name = StringField(required=True)
    age = IntegerField(required=True)
    is_deleted = BooleanField(default=False, required=True)

class CustomerAddress(Entity):
    __kind__ = "address"
    __parent__ = ParentKey(Customer, required=True)

    number = IntegerField(required=True)
    address_one = StringField(required=True)
    address_one = StringField()
    is_default = BooleanField(required=True)
    is_deleted = BooleanField(default=False, required=True)

    class Meta:
        project = "other-project"
        namespace = "other-namespace"

so it overwrites only for that model

Comment on lines -104 to -110
@staticmethod
def _to_camel_case(key: str) -> str:
splited_key = key.split('_')
return splited_key[0] + ''.join(
[x.title() for x in splited_key[1:]]
)

Copy link
Owner Author

Choose a reason for hiding this comment

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

we don't need it anymore

Comment on lines -164 to -172
def _mount_google_entity(self, entity_dict: Dict) -> GoogleEntity:
entity_key = entity_dict.pop("id")
entity = GoogleEntity(entity_key)
for key, value in entity_dict.items():
key_name = self._convert_property_name(key)
entity[key_name] = value

return entity

Copy link
Owner Author

Choose a reason for hiding this comment

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

moved

Comment on lines 45 to 53
def _mount_google_entity(self, entity_dict: Dict, key_case: Callable) -> GoogleEntity:
entity_key = entity_dict.pop("id")
entity = GoogleEntity(entity_key)
for key, value in entity_dict.items():
key_name = key_case(key)
entity[key_name] = value

return entity

Copy link
Owner Author

Choose a reason for hiding this comment

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

I moved it here (from "Entity") because I thought the context made more sense.

Comment on lines +22 to +28
project=project,
namespace=namespace,
credentials=credentials,
client_info=(client_info or _CLIENT_INFO),
client_options=client_options,
_http=_http,
_use_grpc=_use_grpc
Copy link
Owner Author

Choose a reason for hiding this comment

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

these are the default client settings (from google lib)

Comment on lines +16 to +30
self._process_meta(attrs)
self._define_datastore_client()
self._define_case_style(attrs)
self._mount_query()

self._partial_key = KeyField(
entity_kind=self.kind,
project=self._project,
namespace=self._namespace
project=self.project,
namespace=self.namespace
)

self._handle_properties_validation(attrs)
self._handle_required_properties(attrs)
self._handle_properties_default_value(attrs)
self._handle_parent_key(attrs)
Copy link
Owner Author

Choose a reason for hiding this comment

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

I've broken the steps/processes into functions, to make it easier to understand

Copy link

@gahag gahag left a comment

Choose a reason for hiding this comment

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

LGTM!

@exageraldo exageraldo merged commit 0f32661 into main Nov 2, 2021
@exageraldo exageraldo deleted the meta-class-to-override-client-args branch November 2, 2021 03:00
@exageraldo exageraldo self-assigned this Nov 2, 2021
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.

None yet

2 participants