@@ -14,27 +14,36 @@ db.exec(`
1414` ) ;
1515
1616export function saveRound ( round : RoundState ) {
17- const insert = db . prepare ( "INSERT INTO rounds (num, data) VALUES ($num, $data)" ) ;
17+ const insert = db . prepare (
18+ "INSERT INTO rounds (num, data) VALUES ($num, $data)" ,
19+ ) ;
1820 insert . run ( { $num : round . num , $data : JSON . stringify ( round ) } ) ;
1921}
2022
2123export function getRounds ( page : number = 1 , limit : number = 10 ) {
2224 const offset = ( page - 1 ) * limit ;
23- const countQuery = db . query ( "SELECT COUNT(*) as count FROM rounds" ) . get ( ) as { count : number } ;
24- const rows = db . query ( "SELECT data FROM rounds ORDER BY num DESC, id DESC LIMIT $limit OFFSET $offset" )
25+ const countQuery = db . query ( "SELECT COUNT(*) as count FROM rounds" ) . get ( ) as {
26+ count : number ;
27+ } ;
28+ const rows = db
29+ . query (
30+ "SELECT data FROM rounds ORDER BY num DESC, id DESC LIMIT $limit OFFSET $offset" ,
31+ )
2532 . all ( { $limit : limit , $offset : offset } ) as { data : string } [ ] ;
2633 return {
27- rounds : rows . map ( r => JSON . parse ( r . data ) as RoundState ) ,
34+ rounds : rows . map ( ( r ) => JSON . parse ( r . data ) as RoundState ) ,
2835 total : countQuery . count ,
2936 page,
3037 limit,
31- totalPages : Math . ceil ( countQuery . count / limit )
38+ totalPages : Math . ceil ( countQuery . count / limit ) ,
3239 } ;
3340}
3441
3542export function getAllRounds ( ) {
36- const rows = db . query ( "SELECT data FROM rounds ORDER BY num ASC, id ASC" ) . all ( ) as { data : string } [ ] ;
37- return rows . map ( r => JSON . parse ( r . data ) as RoundState ) ;
43+ const rows = db
44+ . query ( "SELECT data FROM rounds ORDER BY num ASC, id ASC" )
45+ . all ( ) as { data : string } [ ] ;
46+ return rows . map ( ( r ) => JSON . parse ( r . data ) as RoundState ) ;
3847}
3948
4049export function clearAllRounds ( ) {
0 commit comments