@@ -141,6 +141,44 @@ impl Database for Sqlite {
141
141
} ) )
142
142
}
143
143
144
+ /// Refer to [`databases::Database::save_persistent_torrent`](crate::core::databases::Database::save_persistent_torrent).
145
+ fn save_persistent_torrent ( & self , info_hash : & InfoHash , completed : u32 ) -> Result < ( ) , Error > {
146
+ let conn = self . pool . get ( ) . map_err ( |e| ( e, DRIVER ) ) ?;
147
+
148
+ let insert = conn. execute (
149
+ "INSERT INTO torrents (info_hash, completed) VALUES (?1, ?2) ON CONFLICT(info_hash) DO UPDATE SET completed = ?2" ,
150
+ [ info_hash. to_string ( ) , completed. to_string ( ) ] ,
151
+ ) ?;
152
+
153
+ if insert == 0 {
154
+ Err ( Error :: InsertFailed {
155
+ location : Location :: caller ( ) ,
156
+ driver : DRIVER ,
157
+ } )
158
+ } else {
159
+ Ok ( ( ) )
160
+ }
161
+ }
162
+
163
+ /// Refer to [`databases::Database::increase_number_of_downloads`](crate::core::databases::Database::increase_number_of_downloads).
164
+ fn increase_number_of_downloads ( & self , info_hash : & InfoHash ) -> Result < ( ) , Error > {
165
+ let conn = self . pool . get ( ) . map_err ( |e| ( e, DRIVER ) ) ?;
166
+
167
+ let update = conn. execute (
168
+ "UPDATE torrents SET completed = completed + 1 WHERE info_hash = ?" ,
169
+ [ info_hash. to_string ( ) ] ,
170
+ ) ?;
171
+
172
+ if update == 0 {
173
+ Err ( Error :: UpdateFailed {
174
+ location : Location :: caller ( ) ,
175
+ driver : DRIVER ,
176
+ } )
177
+ } else {
178
+ Ok ( ( ) )
179
+ }
180
+ }
181
+
144
182
/// Refer to [`databases::Database::load_keys`](crate::core::databases::Database::load_keys).
145
183
fn load_keys ( & self ) -> Result < Vec < authentication:: PeerKey > , Error > {
146
184
let conn = self . pool . get ( ) . map_err ( |e| ( e, DRIVER ) ) ?;
@@ -185,25 +223,6 @@ impl Database for Sqlite {
185
223
Ok ( info_hashes)
186
224
}
187
225
188
- /// Refer to [`databases::Database::save_persistent_torrent`](crate::core::databases::Database::save_persistent_torrent).
189
- fn save_persistent_torrent ( & self , info_hash : & InfoHash , completed : u32 ) -> Result < ( ) , Error > {
190
- let conn = self . pool . get ( ) . map_err ( |e| ( e, DRIVER ) ) ?;
191
-
192
- let insert = conn. execute (
193
- "INSERT INTO torrents (info_hash, completed) VALUES (?1, ?2) ON CONFLICT(info_hash) DO UPDATE SET completed = ?2" ,
194
- [ info_hash. to_string ( ) , completed. to_string ( ) ] ,
195
- ) ?;
196
-
197
- if insert == 0 {
198
- Err ( Error :: InsertFailed {
199
- location : Location :: caller ( ) ,
200
- driver : DRIVER ,
201
- } )
202
- } else {
203
- Ok ( ( ) )
204
- }
205
- }
206
-
207
226
/// Refer to [`databases::Database::get_info_hash_from_whitelist`](crate::core::databases::Database::get_info_hash_from_whitelist).
208
227
fn get_info_hash_from_whitelist ( & self , info_hash : InfoHash ) -> Result < Option < InfoHash > , Error > {
209
228
let conn = self . pool . get ( ) . map_err ( |e| ( e, DRIVER ) ) ?;
0 commit comments