blob: cec75eb6b1ade78e024fa58d45a7870e1efe5e90 [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.TorrentMapper">
<insert id="insertTorrent" >
INSERT INTO torrents (user_id, torrent_name, file_path, info_hash, file_size)
VALUES (#{userId}, #{torrentName}, #{filePath}, UNHEX(#{infoHash}), #{fileSize})
</insert>
<select id="getTorrentByInfoHash" resultType="com.example.g8backend.entity.Torrent">
SELECT
torrent_id,
user_id,
torrent_name,
file_path,
HEX(info_hash) AS infoHash,
file_size
FROM torrents
WHERE info_hash = UNHEX(#{infoHash})
</select>
<select id="getTorrentByTorrentId" resultType="com.example.g8backend.entity.Torrent">
SELECT
torrent_id,
user_id,
torrent_name,
file_path,
HEX(info_hash) AS infoHash,
file_size
FROM torrents
WHERE torrent_id = #{torrentId}
</select>
<select id="selectByInfoHashList" resultType="com.example.g8backend.entity.Torrent" parameterType="list">
SELECT
torrent_id,
user_id,
torrent_name,
file_path,
HEX(info_hash) AS infoHash,
file_size
FROM torrents
WHERE info_hash IN
<foreach collection="infoHashes" item="hash" open="(" separator="," close=")">
UNHEX(#{hash})
</foreach>
</select>
<update id="updateIsRareByInfoHash">
UPDATE torrent
SET israre = #{israre}
WHERE info_hash = #{infoHash}
</update>
</mapper>