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

Question: Why is _queries in QueryCollection private? #10

Closed
realjanpaulus opened this issue Aug 8, 2023 · 1 comment
Closed

Question: Why is _queries in QueryCollection private? #10

realjanpaulus opened this issue Aug 8, 2023 · 1 comment

Comments

@realjanpaulus
Copy link

I would like to execute all queries of my QueryCollection like in the following example:

create_queries = QueryCollection.from_file("src/queries/create.sql")
for _, query in create_queries._queries.items():
    db.execute(query)

Does _queries has to be private? If not, one could access it directly (although it is obviously also now possible to do this, but not recommend because it is private 😉 ) and looping over it.
Alternatively, one could add the following getter function:

def get_queries(self):
    return self._queries
@severinsimmler
Copy link
Member

Good point. I'd suggest to make QueryCollection inherit from collections.abc.Mapping that you can do something like:

queries = QueryCollection.from_file("queries.sql")
for key, query in queries.items():
    db.execute(query)

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