-
Notifications
You must be signed in to change notification settings - Fork 22
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
ClassRowFactory #57
ClassRowFactory #57
Conversation
Signed-off-by: ms2892 <msadiq074@gmail.com>
Hi @ms2892 and thanks for this PR. Would you please write a test case for it? Even better would be to also add documentation for it, with code examples. |
Hi @gusmonod, I would be more than happy to explain what I'm doing here. A detailed discussion of it is described in #42 as I can see that you have linked it with the Issue. As I can understand from the factories defined in This functionality is similar to what has been described in psycopg (https://www.psycopg.org/psycopg3/docs/api/rows.html#psycopg.rows.class_row). Here you pass the reference of the class you wish to get the data as. In factories.py you accomplish this by passing the reference of a function as eventually you wish to use it like a function in the further calls. To mimic the behaviour of a function and also keep track of the class reference, the class row factory can be declared as a class itself. This way when its initialized you can keep the class reference saved as one of its attributes and use the in built call method to use the particular instance like a function. This was described by an example stated within the issue #42 (comment). So to use this particular class row factory you can simply call it like the other dictionaries but with a class reference passed alongside it as described in the snippet below.
If you have any more queries do let me know |
What happens if the types don't match? Or if there is more/less data returned by the query than is expected by the dataclass? |
So there are 4 cases that I could think of
To combat this then the data class will have a datatype validator for post_init method. Something like
This will raise an error 3 & 4) If there is a mismatch of arguments it will raise an error in both cases as
|
5th Case if there is extra stuff returned by the DB.
The error raise in such an input is |
Signed-off-by: ms2892 <msadiq074@gmail.com>
Signed-off-by: ms2892 <msadiq074@gmail.com>
Signed-off-by: ms2892 <msadiq074@gmail.com>
@godlygeek @gusmonod Any updates on the review of this PR? |
Sorry, this is on my list, but I still need to make some time to think about it. |
Closing this for now - see the rationale in #42 (comment). I am willing to resurrect this in the future if we change our |
Issue number of the reported bug or feature request: #
Describe your changes
A clear and concise description of the changes you have made.
Testing performed
Describe the testing you have performed to ensure that the bug has been addressed, or that the new feature works as planned.
Additional context
Add any other context about your contribution here.