以下代码使用了torndb(torndb是对mysqldb的简单封装,调用和使用cursor一致)mysqldb如果查询时传入的参数是值序列,则sql的paramstyle必须是format,即%s作为占位符;如果传入的参数是键值序列,则sql的paramstyle必须是pyformat,即%(xxx)s作为占位符;1.countdef get_all_topics_count_by_node_slug(self, node_slug):
sql = 'SELECT COUNT(0) FROM topic LEFT JOIN node ON topic.node_id = node.id WHERE node.slug = %s'
return self.db.get(sql, node_slug)['COUNT(0)']2.select(分页)def get_all_topics_by_node_slug(self, node_slug, current_page=1, page_size=36, ):
sql = '''SELECT topic.*,
author_user.username as author_username,
...
继续阅读
(37)