blob: 4c90eae7f775ed9d6535eea82dc733785410bcde [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.g8backend.mapper.PeerMapper">
<select id="getPeerByPK">
SELECT * FROM peers
WHERE peer_id = #{peerId} and info_hash = #{infoHash} and passkey = #{passkey}
</select>
<select id="getPeerByInfoHashAndPeerId">
SELECT * FROM peers
WHERE info_hash = #{infoHash} and peer_id = #{peerId}
</select>
<select id="selectAllInfoHashesWithPeers" resultType="String">
SELECT DISTINCT info_hash FROM peers
</select>
<select id="countRecentActivity" resultType="Long" parameterType="String">
SELECT COUNT(*) FROM peers
WHERE info_hash = #{infoHash}
AND last_activity_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
</select>
<select id="selectByInfoHashList" parameterType="list" resultType="com.example.g8backend.entity.Torrent">
SELECT * FROM torrents
WHERE info_hash IN
<foreach item="item" index="index" collection="infoHashes" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<update id="updatePeer">
UPDATE peers
SET uploaded = #{uploaded}, downloaded = #{downloaded}
WHERE peer_id = #{peerId} and info_hash = #{info_hash} and passkey = #{passkey}
</update>
</mapper>