sql语句 转 sqlalchemy的问题

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怎么写?
30秒到达战场
浏览 874回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript