Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

Sort out Query options.#60

Merged
chrisrossi merged 2 commits into
googleapis:masterfrom
chrisrossi:query-options
Apr 5, 2019
Merged

Sort out Query options.#60
chrisrossi merged 2 commits into
googleapis:masterfrom
chrisrossi:query-options

Conversation

@chrisrossi

Copy link
Copy Markdown
Contributor

Make use of the default_options argument to the Query
constructor. Make all arguments to Query.fetch explicit, and perform
the complicated dance of merging all the arguments and options to both
the Query constructor and Query.fetch into a single set of
options for passing to _datastore_query.fetch.

Make use of the ``default_options`` argument to the ``Query``
constructor. Make all arguments to ``Query.fetch`` explicit, and perform
the complicated dance of merging all the arguments and options to both
the ``Query`` constructor and ``Query.fetch`` into a single set of
options for passing to ``_datastore_query.fetch``.

class QueryOptions:
__slots__ = (
"client",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not used in NDB.

class QueryOptions:
__slots__ = (
"client",
# Query options

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've tried to organize these according to which ones are passed to the Query constructor and which ones are passed to Query.fetch. projection is passed to both.

if config is not None and not isinstance(config, QueryOptions):
raise TypeError("Config must be a QueryOptions instance.")

for key in self.__slots__:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored to avoid AttributeError when accessing an attribute that wasn't explicitly passed in.

default = getattr(config, key, None) if config else None
setattr(self, key, kwargs.get(key, default))

def __eq__(self, other):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To support unit tests.

@chrisrossi chrisrossi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2019

@cguardia cguardia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good. Really a lot simpler than before.

@chrisrossi chrisrossi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2019
@chrisrossi chrisrossi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 5, 2019
@chrisrossi chrisrossi merged commit 7dfc776 into googleapis:master Apr 5, 2019
@chrisrossi chrisrossi deleted the query-options branch April 17, 2019 14:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants