@@ -3,13 +3,17 @@ use sqlx::{FromRow, Row, sqlite::SqliteRow};
33#[ derive( Debug ) ]
44pub struct SentSponsorship {
55 pub id : String ,
6+ pub github_id : Option < i64 > ,
7+ pub amount : Option < i64 > ,
68 pub created : Option < chrono:: DateTime < chrono:: Utc > > ,
79}
810
911impl FromRow < ' _ , SqliteRow > for SentSponsorship {
1012 fn from_row ( row : & SqliteRow ) -> sqlx:: Result < Self > {
1113 Ok ( Self {
1214 id : row. try_get ( "id" ) ?,
15+ github_id : row. try_get ( "github_id" ) ?,
16+ amount : row. try_get ( "amount" ) ?,
1317 created : row
1418 . try_get :: < Option < i64 > , _ > ( "created" ) ?
1519 . and_then ( |c| chrono:: DateTime :: < chrono:: Utc > :: from_timestamp ( c, 0 ) ) ,
@@ -33,15 +37,37 @@ pub async fn find_sent_sponsorship(
3337pub async fn insert_sent_sponsorship (
3438 pool : & sqlx:: SqlitePool ,
3539 id : & str ,
40+ github_id : Option < i64 > ,
41+ amount : Option < i64 > ,
3642 created : Option < chrono:: DateTime < chrono:: Utc > > ,
3743) -> Result < ( ) , anyhow:: Error > {
38- sqlx:: query ( "INSERT INTO sent_sponsorships (id, created) VALUES (?, ?)" )
44+ sqlx:: query (
45+ "INSERT INTO sent_sponsorships (id, github_id, amount, created) VALUES (?, ?, ?, ?)" ,
46+ )
47+ . bind ( id)
48+ . bind ( github_id)
49+ . bind ( amount)
50+ . bind (
51+ created
52+ . map ( |c| c. timestamp ( ) )
53+ . unwrap_or_else ( || chrono:: Utc :: now ( ) . timestamp ( ) ) ,
54+ )
55+ . execute ( pool)
56+ . await ?;
57+
58+ Ok ( ( ) )
59+ }
60+
61+ pub async fn backfill_sent_sponsorship (
62+ pool : & sqlx:: SqlitePool ,
63+ id : & str ,
64+ github_id : Option < i64 > ,
65+ amount : Option < i64 > ,
66+ ) -> Result < ( ) , anyhow:: Error > {
67+ sqlx:: query ( "UPDATE sent_sponsorships SET github_id = ?, amount = ? WHERE id = ?" )
68+ . bind ( github_id)
69+ . bind ( amount)
3970 . bind ( id)
40- . bind (
41- created
42- . map ( |c| c. timestamp ( ) )
43- . unwrap_or_else ( || chrono:: Utc :: now ( ) . timestamp ( ) ) ,
44- )
4571 . execute ( pool)
4672 . await ?;
4773
0 commit comments