如何使用 SQLAlchemy 实现内连接?我正在尝试进行简单的聊天
class Base(object):
def __tablename__(self):
return self.__name__.lower()
id = Column(Integer, primary_key=True)
Base = declarative_base(cls=Base)
class PlayerModel(Base):
__tablename__ = 'players'
username = Column(String(30), nullable=False)
email = Column(String(75), nullable=False)
password = Column(String(128), nullable=False)
class MessageModel(Base):
__tablename__ = 'messages'
player_id = Column(Integer,ForeignKey('chats.id'), nullable=False)
message = Column(String(2000), nullable=False)
time = Column(TIMESTAMP, server_default=func.now())
def __repr__(self):
return "<Message('%s')>" % (self.type)
我想阅读比某个日期更年轻的所有消息,结果得到字典列表,例如
[{'username':'x','message':'y','time':'number0'},{'username':'y','message':'z','time':'number1'},
{'username':'x','message':'zz','time':'number'}]
为此,我需要内部加入。如何使它工作?