[PATCH 1/2] db.py: extract commonly used fetch_userid function

Lukas Fleischer lfleischer at archlinux.org
Thu Apr 5 14:17:32 UTC 2018


On Tue, 03 Apr 2018 at 21:19:05, Simon Legner wrote:
> ---
>  aurweb/db.py        |  7 ++++++
>  aurweb/git/serve.py | 68 ++++++++++-------------------------------------------
>  2 files changed, 19 insertions(+), 56 deletions(-)
> 
> diff --git a/aurweb/db.py b/aurweb/db.py
> index 0b58197..bbc674b 100644
> --- a/aurweb/db.py
> +++ b/aurweb/db.py
> @@ -49,3 +49,10 @@ class Connection:
> 
>      def close(self):
>          self._conn.close()
> +
> +    def fetch_userid(self, user):
> +        cur = self.execute("SELECT ID FROM Users WHERE Username = ?", [user])
> +        userid = cur.fetchone()[0]
> +        if userid == 0:
> +            raise aurweb.exceptions.InvalidUserException(user)
> +        return userid
> [...]

Thank you for your contribution.

I agree that it is a good idea to factor out this code fragment, however
I do not think db.py (which currently handles database access in a quite
generic way) is the best place to put this new function. It might be
better to add it to a new module users.py were we can collect other
user-related functions later; ultimately, it would be nice to have
proper ORM but this is at least a step in the right direction...

Regards,
Lukas


More information about the aur-dev mailing list