ifDATABASE.scalar("select count(*) from ip_actions where action = ? and value = ? and ip = ? limit 1","download",level_id,ip).as?(Int64)==0
DATABASE.exec("update levels set downloads = downloads + 1 where id = ?",level_id)
DATABASE.exec("insert into ip_actions (action, value, ip) values (?, ?, ?)","download",level_id,ip)
downloads=DATABASE.scalar("select downloads from levels where id = ?",level_id).as(Int64)
ifdownloads==300
# notify the creator of 300 downloads
account_id,level_name=DATABASE.query_one("select users.account_id, levels.name from levels left join users on users.id = levels.user_id where levels.id = ?",level_id,as:{Int32?,String})
ifaccount_id
ifDATABASE.scalar("select count(*) from notifications where type = \"download_milestone\" and target = ? and account_id = ?",level_id,account_id).as(Int64)==0
ifDATABASE.scalar("select count(*) from ip_actions where action = ? and value = ? and ip = ? limit 1","like_#{type}",item_id,ip).as?(Int64)==0
DATABASE.exec("update #{table} set likes = likes #{sign} 1 where #{column} = ?",item_id)
DATABASE.exec("insert into ip_actions (action, value, ip) values (?, ?, ?)","like_#{type}",item_id,ip)
iftype==1# level
likes=DATABASE.scalar("select likes from #{table} where #{column} = ?",item_id).as(Int64)
iflikes==100
# notify the creator of 100 likes
account_id,level_name=DATABASE.query_one("select users.account_id, #{table}.name from #{table} left join users on users.id = #{table}.user_id where #{table}.#{column} = ?",item_id,as:{Int32?,String})
ifaccount_id
ifDATABASE.scalar("select count(*) from notifications where type = \"like_milestone\" and target = ? and account_id = ?",item_id,account_id).as(Int64)==0