为了账号安全,请及时绑定邮箱和手机立即绑定

sql语句 转 sqlalchemy的问题

sql语句 转 sqlalchemy的问题

30秒到达战场 2019-05-24 15:45:14
MariaDB[blog]>descposts;+---------------+-------------+------+-----+---------+----------------+|Field|Type|Null|Key|Default|Extra|+---------------+-------------+------+-----+---------+----------------+|id|int(11)|NO|PRI|NULL|auto_increment||title|varchar(64)|YES|UNI|NULL|||body|text|YES||NULL|||body_html|text|YES||NULL|||timestamp|datetime|YES||NULL|||author_id|int(11)|YES|MUL|NULL|||comment_count|int(11)|YES||NULL||+---------------+-------------+------+-----+---------+----------------+7rowsinset(0.00sec)MariaDB[blog]>desctalks;+---------------+-------------+------+-----+---------+----------------+|Field|Type|Null|Key|Default|Extra|+---------------+-------------+------+-----+---------+----------------+|id|int(11)|NO|PRI|NULL|auto_increment||title|varchar(64)|YES|UNI|NULL|||body|text|YES||NULL|||body_html|text|YES||NULL|||timestamp|datetime|YES||NULL|||author_id|int(11)|YES|MUL|NULL|||comment_count|int(11)|YES||NULL||+---------------+-------------+------+-----+---------+----------------+这有两张结构相同的表。我向通过时间做聚合排序。sql语句如下:select*from(select*frompostsunionselect*fromtalks)asa_borderbytimestamp;python代码:classPost(db.Model):__tablename__='posts'id=db.Column(db.Integer,primary_key=True)title=db.Column(db.String(64),unique=True,index=True)body=db.Column(db.Text)body_html=db.Column(db.Text)timestamp=db.Column(db.DateTime,default=datetime.utcnow)tags=db.relationship('Tag',secondary=pwt,backref=db.backref('posts',lazy='dynamic'),lazy='dynamic')author_id=db.Column(db.Integer,db.ForeignKey('users.id'))comments=db.relationship('Comment',backref='post',lazy='dynamic')classTalk(db.Model):__tablename__='talks'id=db.Column(db.Integer,primary_key=True)title=db.Column(db.String(64),unique=True,index=True)body=db.Column(db.Text)body_html=db.Column(db.Text)timestamp=db.Column(db.DateTime,default=datetime.utcnow)tags=db.relationship('Tag',secondary=twt,backref=db.backref('talks',lazy='dynamic'),lazy='dynamic')author_id=db.Column(db.Integer,db.ForeignKey('users.id'))comments=db.relationship('Comment',backref='talk',lazy='dynamic')请问转化成sqlalchemy怎么写?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 871 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信