Now that we have a basic user model defined, we can create a Nameko dependency for it. Luckily for us, some of the work has already been done for us in the form of nameko-sqlalchemy, an open-source Nameko dependency that will handle all of the semantics around database sessions and also gives us some very useful Pyest fixtures for testing.
Install nameko-sqlalchemy (version 1.0.0 at the time of writing) by adding it to the requirements/base.in file, and follow the same procedure as earlier to install sqlalchemy.
We will now create a wrapper class that will be used to encapsulate all of the logic around managing users. In users.py, add the following code:
class UserWrapper: def __init__(self, session): self.session ...