model.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:ckanext-tayside 作者: ViderumGlobal 项目源码 文件源码
def update_downloads(resource_id, total_downloads):
    table = get_table('ckanext_tayside_resource_downloads')
    id_col_name = 'resource_id'
    id_col = getattr(table.c, id_col_name)
    s = select([func.count(id_col)],
               id_col == resource_id)
    connection = model.Session.connection()
    count = connection.execute(s).fetchone()
    engine = model.meta.engine

    if count and count[0]:
        engine.execute(table.update()
                       .where(id_col == resource_id)
                       .values(total_downloads=total_downloads))
    else:
        values = {id_col_name: resource_id, 'total_downloads': total_downloads}
        engine.execute(table.insert().values(**values))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号