I'm new in SQLAlchemy and I'm trying to understand some concepts.
Here is a code example without SQLAlchemy:
class Token:
def __init__(self, key):
# generate token based on a string
class User:
def __init__(self, name):
self.name = name
self.token = Token(name)
def check_token(token_to_check)
return self.token.is_valid(token_to_check)
How can I move this to SQLAlchemy?. I think I have to do something like:
class UserDatabase(Base):
__tablename__ = 'testing_sql_alchemy_v2_users'
name = Column(String(256))
token = Column(String(256))
But, when I get the User, token will be a String instead of a Token object. Can I create a Column with my objects?. Example:
token = Column(Token)
If I can't do this, all my objects that use a database must have only "simple" variables (string, int, etc). I think this breaks OOP, right?.