Code Monkey home page Code Monkey logo

zucker's People

Contributors

yrd avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

markhun

zucker's Issues

Support bulk queries

See the Sugar documentation for details here.

The API could look something like this:

async with client.bulk():
    leads_a = Lead.find(Lead.b == 3)
    leads_b = Lead.find(Lead.a == 2)
(leads_a, leads_b) = await asyncio.gather(leads_a, leads_b)

Here, we would require that any requests don't be awaited inside the context manager - that must happen afterwards, once they are all registered in some store / cache / whatever. Then, the results can be awaited and will effectively resolve alltogether.

As an alternative, this might be a bit more consice and doesn't need a context manager:

(leads_a, leads_b) = await client.bulk(
  Lead.find(Lead.b == 3),
  Lead.find(Lead.a == 2),
)

Add some form of support for nullable fields

Currently, an upstream null resolves into this error:

if raw_value is None:
raise AttributeError(
f"Trying to access an undefined field {self.name!r} in record "
f"{type(record)!r}. Either add the field to the module "
f"definition or check for the correct spelling."
)

The first idea would be to add an argument when building the field:

optional_string = model.StringField(optional=True)

Or use a wrapper:

optional_integer = model.OptionalField(model.IntegerField())

Support limiting `.find()` to specific fields

If find() gets a keyword argument fields: Iterable[str], resulting model objects should only cache those fields. There are two possibilities for what could happen when an unavailable field gets accessed:

  • The corresponding value gets fetched. This could however have more implications, as it would mean that __get__ will potentially block / become awaitable depending on the pardigm.
  • An exception is raised. A new method (which is sync or async, depending on context) is defined that fetches all (or only a subset) of the currently unavailable field values. It could be called something like refresh.

The latter approach is probably both easier to implement and better to use in terms of supporting both sync and async frameworks.

authentication token renewal failed with status code 400

Sometimes happens when using the same client for a while. Traceback:

  File "/home/echobot-connector/.local/lib/python3.8/site-packages/zucker/model/view.py", line 532, in __anext__
    new_records = await self.view._module.get_client().bulk(
  File "/home/echobot-connector/.local/lib/python3.8/site-packages/zucker/client/base.py", line 619, in bulk
    await self._ensure_authentication()
  File "/home/echobot-connector/.local/lib/python3.8/site-packages/zucker/client/base.py", line 426, in _ensure_authentication
    self._finalize_authentication(auth_job_name, response_code, response_json)
  File "/home/echobot-connector/.local/lib/python3.8/site-packages/zucker/client/base.py", line 234, in _finalize_authentication
    raise ZuckerException(
zucker.exceptions.ZuckerException: authentication token renewal failed with status code 400

Relevant code:

if not (200 <= response_code < 300):
raise ZuckerException(
f"{auth_job_name} failed with status code {response_code}"
)

Documentation improvements

A few places are still lacking:

  • Implementing custom fields
  • Differences between sync and async implementations (for example, in regards to len())

Remaining field types

This is a placeholder issue for the remaining field types that need to be added:

  • Dropdown / Choices
  • Image
  • Email
  • Datetime
  • Date
  • Boolean
  • String
  • Telephone number
  • Multiple choice
  • URL

Iterators for asynchronous views

Asynchronous views currently don't support the iteration protocol, so this isn't possible (although mentioned in the docs):

async for lead in Leads.find():
    print(lead)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.