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))
评论列表
文章目录