@@ -8,6 +8,7 @@ use rusqlite::Row;
88use serde_json:: Map ;
99use serde_json:: Value ;
1010use std:: sync:: Arc ;
11+ use time:: format_description:: well_known:: Rfc3339 ;
1112use time:: macros:: format_description;
1213use time:: Date ;
1314use time:: OffsetDateTime ;
@@ -61,10 +62,10 @@ impl ReportRepo {
6162
6263 pub async fn select_updated_since (
6364 & self ,
64- updated_since : & str ,
65+ updated_since : & OffsetDateTime ,
6566 limit : Option < i64 > ,
6667 ) -> Result < Vec < Report > > {
67- let updated_since = updated_since. to_string ( ) ;
68+ let updated_since = updated_since. clone ( ) ;
6869 self . pool
6970 . get ( )
7071 . await ?
@@ -188,7 +189,7 @@ impl Report {
188189 }
189190
190191 pub fn select_updated_since (
191- updated_since : & str ,
192+ updated_since : & OffsetDateTime ,
192193 limit : Option < i64 > ,
193194 conn : & Connection ,
194195 ) -> Result < Vec < Report > > {
@@ -212,7 +213,44 @@ impl Report {
212213 Ok ( conn
213214 . prepare ( query) ?
214215 . query_map (
215- named_params ! { ":updated_since" : updated_since, ":limit" : limit. unwrap_or( i64 :: MAX ) } ,
216+ named_params ! {
217+ ":updated_since" : updated_since. format( & Rfc3339 ) ?,
218+ ":limit" : limit. unwrap_or( i64 :: MAX ) ,
219+ } ,
220+ mapper ( ) ,
221+ ) ?
222+ . collect :: < Result < Vec < Report > , _ > > ( ) ?)
223+ }
224+
225+ pub fn select_by_date (
226+ date : & Date ,
227+ limit : Option < i64 > ,
228+ conn : & Connection ,
229+ ) -> Result < Vec < Report > > {
230+ let query = r#"
231+ SELECT
232+ r.rowid,
233+ r.area_id,
234+ json_extract(a.tags, '$.url_alias'),
235+ r.date,
236+ r.tags,
237+ r.created_at,
238+ r.updated_at,
239+ r.deleted_at
240+ FROM report r
241+ LEFT JOIN area a ON a.rowid = r.area_id
242+ WHERE r.date = :date
243+ ORDER BY r.updated_at, r.rowid
244+ LIMIT :limit
245+ "# ;
246+
247+ Ok ( conn
248+ . prepare ( query) ?
249+ . query_map (
250+ named_params ! {
251+ ":date" : date. to_string( ) ,
252+ ":limit" : limit. unwrap_or( i64 :: MAX ) ,
253+ } ,
216254 mapper ( ) ,
217255 ) ?
218256 . collect :: < Result < Vec < Report > , _ > > ( ) ?)
@@ -384,7 +422,7 @@ mod test {
384422 . await ?;
385423 let reports = state
386424 . report_repo
387- . select_updated_since ( " 2000-01-01" , None )
425+ . select_updated_since ( & datetime ! ( 2000 -01 -01 00 : 00 UTC ) , None )
388426 . await ?;
389427 assert_eq ! ( 1 , reports. len( ) ) ;
390428 Ok ( ( ) )
@@ -410,7 +448,7 @@ mod test {
410448 . await ?;
411449 let reports = state
412450 . report_repo
413- . select_updated_since ( " 2000-01-01" , None )
451+ . select_updated_since ( & datetime ! ( 2000 -01 -01 00 : 00 UTC ) , None )
414452 . await ?;
415453 assert_eq ! ( 3 , reports. len( ) ) ;
416454 Ok ( ( ) )
@@ -450,7 +488,7 @@ mod test {
450488 2 ,
451489 state
452490 . report_repo
453- . select_updated_since( " 2020-01-01T00: 00:00Z" , None )
491+ . select_updated_since( & datetime! ( 2020 -01 -01 00 : 00 UTC ) , None )
454492 . await ?
455493 . len( )
456494 ) ;
0 commit comments