Skip to content
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

Support for dataclasses? #52

Open
olemb opened this issue Dec 21, 2020 · 1 comment
Open

Support for dataclasses? #52

olemb opened this issue Dec 21, 2020 · 1 comment

Comments

@olemb
Copy link
Owner

olemb commented Dec 21, 2020

This is not something we need to support directly in the code, but it would be nice to have a documented way to create dataclasses from records.

I think it should be possible to create dataclasses dynamically be inspecting the DBF object, but perhaps it is best after all to create the dataclass manually.

@olemb
Copy link
Owner Author

olemb commented May 11, 2021

That's something I'd love to add. How about this API?

@dataclass
class Customer:
    id: int
    name: str

dbf = dbfread.DBF('customers.dbf', recordfactory=Customer)    

This might already work. I haven't tested it.

We could also add support for dynamic dataclasses without adding any new options:

dbf = dbfread.DBF('customers.dbf', recordfactory=dataclass)

This should be fairly easy to implement.

Thanks for the suggestion! If I had created dbfread today I would have made dynamically created dataclasses the default instead of dictionaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant