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

Using a littletable.Table index on id using 'by' instead of 'where' #1

Open
ptmcg opened this issue Jul 10, 2021 · 0 comments
Open

Comments

@ptmcg
Copy link

ptmcg commented Jul 10, 2021

return self.__tasks.where(id=id)[0]

So happy to see that littletable is useful in your project.

Since you created a unique index on the "id" attribute, you can replace this line with:

return self.__tasks.by.id[id]

which will either return the matching task, or raise KeyError.

In the end, it is equivalent to the code you have now, just wanted to make you aware of the table.by.<index_name> form of using indexed attributes.

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