| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| *args, | ||
| prefetch=None, | ||
| timeout=None, | ||
| record_class=None |
There was a problem hiding this comment.
Instead of adding record_class everywhere I'd allow passing it to the constructor. Or add a set_record_class_factory method.
Sorry, something went wrong.
There was a problem hiding this comment.
Is there any evidence that users want multiple different record types on one connection?
Sorry, something went wrong.
There was a problem hiding this comment.
The entire impetus of this push was from #577, where the record_class is used as a TypeDict-like typehint for the result, which gets typechecked also.
I'd allow passing it to the constructor.
It is also allowed to be passed in the constructor if you want a connection-wide subclass.
Sorry, something went wrong.
|
@elprans is this PR ok to be merged? I'm really looking forward for this and the typings PR 😄 |
Sorry, something went wrong.
Add the new `record_class` parameter to the `create_pool()` and `connect()` functions, as well as to the `cursor()`, `prepare()`, `fetch()` and `fetchrow()` connection methods. This not only allows adding custom functionality to the returned objects, but also assists with typing (see #577 for discussion). Fixes: #40.
|
@elprans Can you provide an example how to implement custom record_class with dot-notation? |
Sorry, something went wrong.
Not sure if this is correct but should work class MyRecord(Record):
def __getattr__(self, item):
return self.get(item) |
Sorry, something went wrong.
|
#960 adds an example of this to the FAQ item. |
Sorry, something went wrong.
|
I tried implementing that example, but I kept getting errors from the GraphQL execution engine because it passed __await__ (via hasattr()) and received None — based on my reading of the docs, you're supposed to raise AttributeError if the lookup fails: https://docs.python.org/3/reference/datamodel.html#object.__getattr__ So I updated the code to this, and it started working: class AttrRecord( asyncpg.Record ):
def __getattr__( self, name ):
if name not in self:
raise AttributeError
return self[ name ] |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Add the new record_class parameter to the create_pool() and
connect() functions, as well as to the cursor(), prepare(),
fetch() and fetchrow() connection methods.
This not only allows adding custom functionality to the returned
objects, but also assists with typing (see #577 for discussion).
Fixes: #40.