-
Notifications
You must be signed in to change notification settings - Fork 0
Add batching
flag to SQLAlchemyObjectType
and ORMField
#2
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
Conversation
|
||
if not _type: | ||
batching_ = batching if is_selectin_available else False | ||
connection_field_factory_ = connection_field_factory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this allocation ?
**field_kwargs | ||
) | ||
resolver = get_custom_resolver(obj_type, orm_field_name) | ||
if resolver is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find this syntax very readable. maybe something like that ?
if resolver is None: | |
if resolver is None and batching_: |
) | ||
resolver = get_custom_resolver(obj_type, orm_field_name) | ||
if resolver is None: | ||
resolver = get_batch_resolver(relationship_prop) if batching_ else \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolver = get_batch_resolver(relationship_prop) if batching_ else \ | |
resolver = get_batch_resolver(relationship_prop) |
resolver = get_custom_resolver(obj_type, orm_field_name) | ||
if resolver is None: | ||
resolver = get_batch_resolver(relationship_prop) if batching_ else \ | ||
get_attr_resolver(obj_type, relationship_prop.key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_attr_resolver(obj_type, relationship_prop.key) | |
elif resolver is None: | |
resolver = get_attr_resolver(obj_type, relationship_prop.key) |
if connection_field_factory_ is None: | ||
connection_field_factory_ = BatchSQLAlchemyConnectionField.from_relationship if batching_ else \ | ||
default_connection_field_factory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same thing here, I think :)
resolver = get_custom_resolver(obj_type, orm_field_name) or get_attr_resolver(obj_type, attr_name) | ||
|
||
if isinstance(attr, ColumnProperty): | ||
field = convert_sqlalchemy_column( | ||
attr, | ||
registry, | ||
custom_resolver or _get_attr_resolver(obj_type, orm_field_name, attr_name), | ||
**orm_field.kwargs | ||
) | ||
field = convert_sqlalchemy_column(attr, registry, resolver, **orm_field.kwargs) | ||
elif isinstance(attr, RelationshipProperty): | ||
batching_ = orm_field.kwargs.pop('batching', batching) | ||
field = convert_sqlalchemy_relationship( | ||
attr, | ||
registry, | ||
connection_field_factory, | ||
custom_resolver or _get_relationship_resolver(obj_type, attr, attr_name), | ||
**orm_field.kwargs | ||
) | ||
attr, obj_type, connection_field_factory, batching_, attr_name, | ||
orm_field_name, **orm_field.kwargs) | ||
elif isinstance(attr, CompositeProperty): | ||
if attr_name != orm_field_name or orm_field.kwargs: | ||
# TODO Add a way to override composite property fields | ||
raise ValueError( | ||
"ORMField kwargs for composite fields must be empty. " | ||
"Field: {}.{}".format(obj_type.__name__, orm_field_name)) | ||
field = convert_sqlalchemy_composite( | ||
attr, | ||
registry, | ||
custom_resolver or _get_attr_resolver(obj_type, orm_field_name, attr_name), | ||
) | ||
field = convert_sqlalchemy_composite(attr, registry, resolver) | ||
elif isinstance(attr, hybrid_property): | ||
field = convert_sqlalchemy_hybrid_method( | ||
attr, | ||
custom_resolver or _get_attr_resolver(obj_type, orm_field_name, attr_name), | ||
**orm_field.kwargs | ||
) | ||
field = convert_sqlalchemy_hybrid_method(attr, resolver, **orm_field.kwargs) | ||
else: | ||
raise Exception('Property type is not supported') # Should never happen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice cleanup ;)
@Nabellaleen Thanks for the review. Unfortunately, I have to close this one and send a new one in the |
Preview