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

[Feature request] Define data access interface #99

Open
ivaigult opened this issue Oct 23, 2023 · 1 comment
Open

[Feature request] Define data access interface #99

ivaigult opened this issue Oct 23, 2023 · 1 comment

Comments

@ivaigult
Copy link

I really appreciate spyql flexibility and the fact that it supports many formats, but what if I want to add my own format support?:slightly_smiling_face:

My use case: I have custom data format, and I parse it to dataclasses. For example:

@dataclass
class MyData:
    field_one: str
    field_two: str

Now, I want to be able to run queries on a list of these dataclasses instances:

data = [DataClass("one", "1"), DataClass("two", "2"), DataClass("three", "3")]

# ...

query = Query("""SELECT row.field_one FROM data""")
query(data)

Of course, this does not work, since the attributes are queried directly with dict.__getitem__.

I understand, I can use dataclasses.asdict, but this approach is not flexible enough, because I also want to use arbitrary properties and functions in my queries. This would mean that everything should be converted to dictionaries ahead of time, what might be costly.

Could you please add some abstraction to allow custom types in queries? Something like:

@dataclass
class MyData(spyql.Row):
   # ...

   def get_column(self, name: str) -> types.Any:
       # ...
@dcmoura
Copy link
Owner

dcmoura commented Oct 25, 2023

Hi! Thank you so much for the feedback.

The idea is great! I cannot implement it right now (no bandwidth at the moment), but you are welcomed to submit a PR :-) Let me know before start coding if you would to like to contribute. Thanks!

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

2 participants