blob: 4c90eae7f775ed9d6535eea82dc733785410bcde [file] [log] [blame]
wuchimedesdb9fe682025-04-22 19:24:11 +08001<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
3 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4<mapper namespace="com.example.g8backend.mapper.PeerMapper">
5 <select id="getPeerByPK">
6 SELECT * FROM peers
7 WHERE peer_id = #{peerId} and info_hash = #{infoHash} and passkey = #{passkey}
8 </select>
9 <select id="getPeerByInfoHashAndPeerId">
10 SELECT * FROM peers
11 WHERE info_hash = #{infoHash} and peer_id = #{peerId}
12 </select>
223010719e7ca122025-06-03 23:26:44 +080013 <select id="selectAllInfoHashesWithPeers" resultType="String">
14 SELECT DISTINCT info_hash FROM peers
15 </select>
16
17 <select id="countRecentActivity" resultType="Long" parameterType="String">
18 SELECT COUNT(*) FROM peers
19 WHERE info_hash = #{infoHash}
20 AND last_activity_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
21 </select>
22 <select id="selectByInfoHashList" parameterType="list" resultType="com.example.g8backend.entity.Torrent">
23 SELECT * FROM torrents
24 WHERE info_hash IN
25 <foreach item="item" index="index" collection="infoHashes" open="(" separator="," close=")">
26 #{item}
27 </foreach>
28 </select>
wuchimedesdb9fe682025-04-22 19:24:11 +080029 <update id="updatePeer">
30 UPDATE peers
31 SET uploaded = #{uploaded}, downloaded = #{downloaded}
32 WHERE peer_id = #{peerId} and info_hash = #{info_hash} and passkey = #{passkey}
33 </update>
34</mapper>