0000: 75 73 65 20 73 74 64 3a 3a 7b 0a 09 62 6f 72 72 use std::{..borr
0010: 6f 77 3a 3a 43 6f 77 2c 0a 09 66 6d 74 2c 0a 7d ow::Cow,..fmt,.}
0020: 3b 0a 0a 75 73 65 20 61 73 79 6e 63 5f 73 74 64 ;..use async_std
0030: 3a 3a 73 79 6e 63 3a 3a 7b 0a 09 41 72 63 2c 0a ::sync::{..Arc,.
0040: 09 4d 75 74 65 78 2c 0a 7d 3b 0a 75 73 65 20 63 .Mutex,.};.use c
0050: 68 72 6f 6e 6f 3a 3a 7b 0a 09 44 61 74 65 54 69 hrono::{..DateTi
0060: 6d 65 2c 0a 09 46 69 78 65 64 4f 66 66 73 65 74 me,..FixedOffset
0070: 2c 0a 09 4c 6f 63 61 6c 2c 0a 7d 3b 0a 75 73 65 ,..Local,.};.use
0080: 20 73 71 6c 78 3a 3a 7b 0a 09 50 6f 73 74 67 72 sqlx::{..Postgr
0090: 65 73 2c 0a 09 52 6f 77 2c 0a 09 70 6f 73 74 67 es,..Row,..postg
00a0: 72 65 73 3a 3a 50 67 50 6f 6f 6c 4f 70 74 69 6f res::PgPoolOptio
00b0: 6e 73 2c 0a 09 70 6f 6f 6c 3a 3a 50 6f 6f 6c 43 ns,..pool::PoolC
00c0: 6f 6e 6e 65 63 74 69 6f 6e 2c 0a 7d 3b 0a 75 73 onnection,.};.us
00d0: 65 20 73 74 61 63 6b 65 64 5f 65 72 72 6f 72 73 e stacked_errors
00e0: 3a 3a 7b 0a 09 52 65 73 75 6c 74 2c 0a 09 53 74 ::{..Result,..St
00f0: 61 63 6b 61 62 6c 65 45 72 72 2c 0a 09 62 61 69 ackableErr,..bai
0100: 6c 2c 0a 7d 3b 0a 0a 23 5b 64 65 72 69 76 65 28 l,.};..#[derive(
0110: 73 71 6c 78 3a 3a 46 72 6f 6d 52 6f 77 2c 20 44 sqlx::FromRow, D
0120: 65 62 75 67 29 5d 0a 70 75 62 20 73 74 72 75 63 ebug)].pub struc
0130: 74 20 4c 69 73 74 20 7b 0a 09 70 75 62 20 73 6f t List {..pub so
0140: 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 0a 09 70 urce_id: i32,..p
0150: 75 62 20 63 68 61 6e 6e 65 6c 3a 20 53 74 72 69 ub channel: Stri
0160: 6e 67 2c 0a 09 70 75 62 20 65 6e 61 62 6c 65 64 ng,..pub enabled
0170: 3a 20 62 6f 6f 6c 2c 0a 09 70 75 62 20 75 72 6c : bool,..pub url
0180: 3a 20 53 74 72 69 6e 67 2c 0a 09 70 75 62 20 69 : String,..pub i
0190: 76 5f 68 61 73 68 3a 20 4f 70 74 69 6f 6e 3c 53 v_hash: Option<S
01a0: 74 72 69 6e 67 3e 2c 0a 09 70 75 62 20 75 72 6c tring>,..pub url
01b0: 5f 72 65 3a 20 4f 70 74 69 6f 6e 3c 53 74 72 69 _re: Option<Stri
01c0: 6e 67 3e 2c 0a 7d 0a 0a 69 6d 70 6c 20 66 6d 74 ng>,.}..impl fmt
01d0: 3a 3a 44 69 73 70 6c 61 79 20 66 6f 72 20 4c 69 ::Display for Li
01e0: 73 74 20 7b 0a 09 66 6e 20 66 6d 74 28 26 73 65 st {..fn fmt(&se
01f0: 6c 66 2c 20 66 3a 20 26 6d 75 74 20 66 6d 74 3a lf, f: &mut fmt:
0200: 3a 46 6f 72 6d 61 74 74 65 72 3c 27 5f 3e 29 20 :Formatter<'_>)
0210: 2d 3e 20 73 74 64 3a 3a 72 65 73 75 6c 74 3a 3a -> std::result::
0220: 52 65 73 75 6c 74 3c 28 29 2c 20 66 6d 74 3a 3a Result<(), fmt::
0230: 45 72 72 6f 72 3e 20 7b 0a 09 09 77 72 69 74 65 Error> {...write
0240: 21 28 66 2c 20 22 23 7b 7d 20 5c 5c 2a ef b8 8f !(f, "#{} \\*ļø
0250: e2 83 a3 20 60 7b 7d 60 20 7b 7d 5c 6e f0 9f 94 ⣠`{}` {}\nš
0260: 97 20 60 7b 7d 60 22 2c 20 73 65 6c 66 2e 73 6f `{}`", self.so
0270: 75 72 63 65 5f 69 64 2c 20 73 65 6c 66 2e 63 68 urce_id, self.ch
0280: 61 6e 6e 65 6c 2c 0a 09 09 09 6d 61 74 63 68 20 annel,....match
0290: 73 65 6c 66 2e 65 6e 61 62 6c 65 64 20 7b 0a 09 self.enabled {..
02a0: 09 09 09 74 72 75 65 20 20 3d 3e 20 22 f0 9f 94 ...true => "š
02b0: 84 20 65 6e 61 62 6c 65 64 22 2c 0a 09 09 09 09 enabled",.....
02c0: 66 61 6c 73 65 20 3d 3e 20 22 e2 9b 94 20 64 69 false => "ā di
02d0: 73 61 62 6c 65 64 22 2c 0a 09 09 09 7d 2c 20 73 sabled",....}, s
02e0: 65 6c 66 2e 75 72 6c 29 3f 3b 0a 09 09 69 66 20 elf.url)?;...if
02f0: 6c 65 74 20 53 6f 6d 65 28 69 76 5f 68 61 73 68 let Some(iv_hash
0300: 29 20 3d 20 26 73 65 6c 66 2e 69 76 5f 68 61 73 ) = &self.iv_has
0310: 68 20 7b 0a 09 09 09 77 72 69 74 65 21 28 66 2c h {....write!(f,
0320: 20 22 5c 6e 49 56 3a 20 60 7b 69 76 5f 68 61 73 "\nIV: `{iv_has
0330: 68 7d 60 22 29 3f 3b 0a 09 09 7d 0a 09 09 69 66 h}`")?;...}...if
0340: 20 6c 65 74 20 53 6f 6d 65 28 75 72 6c 5f 72 65 let Some(url_re
0350: 29 20 3d 20 26 73 65 6c 66 2e 75 72 6c 5f 72 65 ) = &self.url_re
0360: 20 7b 0a 09 09 09 77 72 69 74 65 21 28 66 2c 20 {....write!(f,
0370: 22 5c 6e 52 45 3a 20 60 7b 75 72 6c 5f 72 65 7d "\nRE: `{url_re}
0380: 60 22 29 3f 3b 0a 09 09 7d 0a 09 09 4f 6b 28 28 `")?;...}...Ok((
0390: 29 29 0a 09 7d 0a 7d 0a 0a 23 5b 64 65 72 69 76 ))..}.}..#[deriv
03a0: 65 28 73 71 6c 78 3a 3a 46 72 6f 6d 52 6f 77 2c e(sqlx::FromRow,
03b0: 20 44 65 62 75 67 29 5d 0a 70 75 62 20 73 74 72 Debug)].pub str
03c0: 75 63 74 20 53 6f 75 72 63 65 20 7b 0a 09 70 75 uct Source {..pu
03d0: 62 20 63 68 61 6e 6e 65 6c 5f 69 64 3a 20 69 36 b channel_id: i6
03e0: 34 2c 0a 09 70 75 62 20 75 72 6c 3a 20 53 74 72 4,..pub url: Str
03f0: 69 6e 67 2c 0a 09 70 75 62 20 69 76 5f 68 61 73 ing,..pub iv_has
0400: 68 3a 20 4f 70 74 69 6f 6e 3c 53 74 72 69 6e 67 h: Option<String
0410: 3e 2c 0a 09 70 75 62 20 6f 77 6e 65 72 3a 20 69 >,..pub owner: i
0420: 36 34 2c 0a 09 70 75 62 20 75 72 6c 5f 72 65 3a 64,..pub url_re:
0430: 20 4f 70 74 69 6f 6e 3c 53 74 72 69 6e 67 3e 2c Option<String>,
0440: 0a 7d 0a 0a 23 5b 64 65 72 69 76 65 28 73 71 6c .}..#[derive(sql
0450: 78 3a 3a 46 72 6f 6d 52 6f 77 29 5d 0a 70 75 62 x::FromRow)].pub
0460: 20 73 74 72 75 63 74 20 51 75 65 75 65 20 7b 0a struct Queue {.
0470: 09 70 75 62 20 73 6f 75 72 63 65 5f 69 64 3a 20 .pub source_id:
0480: 4f 70 74 69 6f 6e 3c 69 33 32 3e 2c 0a 09 70 75 Option<i32>,..pu
0490: 62 20 6e 65 78 74 5f 66 65 74 63 68 3a 20 4f 70 b next_fetch: Op
04a0: 74 69 6f 6e 3c 44 61 74 65 54 69 6d 65 3c 4c 6f tion<DateTime<Lo
04b0: 63 61 6c 3e 3e 2c 0a 09 70 75 62 20 6f 77 6e 65 cal>>,..pub owne
04c0: 72 3a 20 4f 70 74 69 6f 6e 3c 69 36 34 3e 2c 0a r: Option<i64>,.
04d0: 09 70 75 62 20 6c 61 73 74 5f 73 63 72 61 70 65 .pub last_scrape
04e0: 3a 20 44 61 74 65 54 69 6d 65 3c 4c 6f 63 61 6c : DateTime<Local
04f0: 3e 2c 0a 7d 0a 0a 23 5b 64 65 72 69 76 65 28 43 >,.}..#[derive(C
0500: 6c 6f 6e 65 29 5d 0a 70 75 62 20 73 74 72 75 63 lone)].pub struc
0510: 74 20 44 62 20 28 0a 09 41 72 63 3c 4d 75 74 65 t Db (..Arc<Mute
0520: 78 3c 73 71 6c 78 3a 3a 50 6f 6f 6c 3c 73 71 6c x<sqlx::Pool<sql
0530: 78 3a 3a 50 6f 73 74 67 72 65 73 3e 3e 3e 2c 0a x::Postgres>>>,.
0540: 29 3b 0a 0a 69 6d 70 6c 20 44 62 20 7b 0a 09 70 );..impl Db {..p
0550: 75 62 20 66 6e 20 6e 65 77 20 28 70 67 75 72 69 ub fn new (pguri
0560: 3a 20 26 73 74 72 29 20 2d 3e 20 52 65 73 75 6c : &str) -> Resul
0570: 74 3c 44 62 3e 20 7b 0a 09 09 4f 6b 28 44 62 20 t<Db> {...Ok(Db
0580: 28 0a 09 09 09 41 72 63 3a 3a 6e 65 77 28 4d 75 (....Arc::new(Mu
0590: 74 65 78 3a 3a 6e 65 77 28 50 67 50 6f 6f 6c 4f tex::new(PgPoolO
05a0: 70 74 69 6f 6e 73 3a 3a 6e 65 77 28 29 0a 09 09 ptions::new()...
05b0: 09 09 2e 6d 61 78 5f 63 6f 6e 6e 65 63 74 69 6f ...max_connectio
05c0: 6e 73 28 35 29 0a 09 09 09 09 2e 61 63 71 75 69 ns(5)......acqui
05d0: 72 65 5f 74 69 6d 65 6f 75 74 28 73 74 64 3a 3a re_timeout(std::
05e0: 74 69 6d 65 3a 3a 44 75 72 61 74 69 6f 6e 3a 3a time::Duration::
05f0: 6e 65 77 28 33 30 30 2c 20 30 29 29 0a 09 09 09 new(300, 0))....
0600: 09 2e 69 64 6c 65 5f 74 69 6d 65 6f 75 74 28 73 ..idle_timeout(s
0610: 74 64 3a 3a 74 69 6d 65 3a 3a 44 75 72 61 74 69 td::time::Durati
0620: 6f 6e 3a 3a 6e 65 77 28 36 30 2c 20 30 29 29 0a on::new(60, 0)).
0630: 09 09 09 09 2e 63 6f 6e 6e 65 63 74 5f 6c 61 7a .....connect_laz
0640: 79 28 70 67 75 72 69 29 0a 09 09 09 09 2e 73 74 y(pguri)......st
0650: 61 63 6b 28 29 3f 29 29 2c 0a 09 09 29 29 0a 09 ack()?)),...))..
0660: 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e }...pub async fn
0670: 20 62 65 67 69 6e 28 26 73 65 6c 66 29 20 2d 3e begin(&self) ->
0680: 20 52 65 73 75 6c 74 3c 43 6f 6e 6e 3e 20 7b 0a Result<Conn> {.
0690: 09 09 6c 65 74 20 70 6f 6f 6c 20 3d 20 73 65 6c ..let pool = sel
06a0: 66 2e 30 2e 6c 6f 63 6b 5f 61 72 63 28 29 2e 61 f.0.lock_arc().a
06b0: 77 61 69 74 3b 0a 09 09 6c 65 74 20 63 6f 6e 6e wait;...let conn
06c0: 20 3d 20 43 6f 6e 6e 20 28 20 70 6f 6f 6c 2e 61 = Conn ( pool.a
06d0: 63 71 75 69 72 65 28 29 2e 61 77 61 69 74 2e 73 cquire().await.s
06e0: 74 61 63 6b 28 29 3f 20 29 3b 0a 09 09 4f 6b 28 tack()? );...Ok(
06f0: 63 6f 6e 6e 29 0a 09 7d 0a 7d 0a 0a 70 75 62 20 conn)..}.}..pub
0700: 73 74 72 75 63 74 20 43 6f 6e 6e 20 28 0a 09 50 struct Conn (..P
0710: 6f 6f 6c 43 6f 6e 6e 65 63 74 69 6f 6e 3c 50 6f oolConnection<Po
0720: 73 74 67 72 65 73 3e 2c 0a 29 3b 0a 0a 69 6d 70 stgres>,.);..imp
0730: 6c 20 43 6f 6e 6e 20 7b 0a 09 70 75 62 20 61 73 l Conn {..pub as
0740: 79 6e 63 20 66 6e 20 61 64 64 5f 70 6f 73 74 20 ync fn add_post
0750: 28 26 6d 75 74 20 73 65 6c 66 2c 20 73 6f 75 72 (&mut self, sour
0760: 63 65 5f 69 64 3a 20 69 33 32 2c 20 64 61 74 65 ce_id: i32, date
0770: 3a 20 26 44 61 74 65 54 69 6d 65 3c 46 69 78 65 : &DateTime<Fixe
0780: 64 4f 66 66 73 65 74 3e 2c 20 70 6f 73 74 5f 75 dOffset>, post_u
0790: 72 6c 3a 20 26 73 74 72 29 20 2d 3e 20 52 65 73 rl: &str) -> Res
07a0: 75 6c 74 3c 28 29 3e 20 7b 0a 09 09 73 71 6c 78 ult<()> {...sqlx
07b0: 3a 3a 71 75 65 72 79 28 22 69 6e 73 65 72 74 20 ::query("insert
07c0: 69 6e 74 6f 20 72 73 73 74 67 5f 70 6f 73 74 20 into rsstg_post
07d0: 28 73 6f 75 72 63 65 5f 69 64 2c 20 70 6f 73 74 (source_id, post
07e0: 65 64 2c 20 75 72 6c 29 20 76 61 6c 75 65 73 20 ed, url) values
07f0: 28 24 31 2c 20 24 32 2c 20 24 33 29 3b 22 29 0a ($1, $2, $3);").
0800: 09 09 09 2e 62 69 6e 64 28 73 6f 75 72 63 65 5f ....bind(source_
0810: 69 64 29 0a 09 09 09 2e 62 69 6e 64 28 64 61 74 id).....bind(dat
0820: 65 29 0a 09 09 09 2e 62 69 6e 64 28 70 6f 73 74 e).....bind(post
0830: 5f 75 72 6c 29 0a 09 09 09 2e 65 78 65 63 75 74 _url).....execut
0840: 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e e(&mut *self.0).
0850: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a await.stack()?;.
0860: 09 09 4f 6b 28 28 29 29 0a 09 7d 0a 0a 09 70 75 ..Ok(())..}...pu
0870: 62 20 61 73 79 6e 63 20 66 6e 20 63 6c 65 61 6e b async fn clean
0880: 20 3c 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c <I> (&mut self,
0890: 20 73 6f 75 72 63 65 5f 69 64 3a 20 69 33 32 2c source_id: i32,
08a0: 20 6f 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 owner: I) -> Re
08b0: 73 75 6c 74 3c 43 6f 77 3c 27 5f 2c 20 73 74 72 sult<Cow<'_, str
08c0: 3e 3e 0a 09 77 68 65 72 65 20 49 3a 20 49 6e 74 >>..where I: Int
08d0: 6f 3c 69 36 34 3e 20 7b 0a 09 09 6d 61 74 63 68 o<i64> {...match
08e0: 20 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 64 65 sqlx::query("de
08f0: 6c 65 74 65 20 66 72 6f 6d 20 72 73 73 74 67 5f lete from rsstg_
0900: 70 6f 73 74 20 70 20 75 73 69 6e 67 20 72 73 73 post p using rss
0910: 74 67 5f 73 6f 75 72 63 65 20 73 20 77 68 65 72 tg_source s wher
0920: 65 20 70 2e 73 6f 75 72 63 65 5f 69 64 20 3d 20 e p.source_id =
0930: 24 31 20 61 6e 64 20 6f 77 6e 65 72 20 3d 20 24 $1 and owner = $
0940: 32 20 61 6e 64 20 70 2e 73 6f 75 72 63 65 5f 69 2 and p.source_i
0950: 64 20 3d 20 73 2e 73 6f 75 72 63 65 5f 69 64 3b d = s.source_id;
0960: 22 29 0a 09 09 09 2e 62 69 6e 64 28 73 6f 75 72 ").....bind(sour
0970: 63 65 5f 69 64 29 0a 09 09 09 2e 62 69 6e 64 28 ce_id).....bind(
0980: 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 09 owner.into())...
0990: 09 2e 65 78 65 63 75 74 65 28 26 6d 75 74 20 2a ..execute(&mut *
09a0: 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 self.0).await.st
09b0: 61 63 6b 28 29 3f 2e 72 6f 77 73 5f 61 66 66 65 ack()?.rows_affe
09c0: 63 74 65 64 28 29 20 7b 0a 09 09 09 30 20 3d 3e cted() {....0 =>
09d0: 20 7b 20 4f 6b 28 22 4e 6f 20 64 61 74 61 20 66 { Ok("No data f
09e0: 6f 75 6e 64 20 66 6f 75 6e 64 2e 22 2e 69 6e 74 ound found.".int
09f0: 6f 28 29 29 20 7d 2c 0a 09 09 09 78 20 3d 3e 20 o()) },....x =>
0a00: 7b 20 4f 6b 28 66 6f 72 6d 61 74 21 28 22 7b 78 { Ok(format!("{x
0a10: 7d 20 70 6f 73 74 73 20 70 75 72 67 65 64 2e 22 } posts purged."
0a20: 29 2e 69 6e 74 6f 28 29 29 20 7d 2c 0a 09 09 7d ).into()) },...}
0a30: 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 ..}...pub async
0a40: 66 6e 20 64 65 6c 65 74 65 20 3c 49 3e 20 28 26 fn delete <I> (&
0a50: 6d 75 74 20 73 65 6c 66 2c 20 73 6f 75 72 63 65 mut self, source
0a60: 5f 69 64 3a 20 69 33 32 2c 20 6f 77 6e 65 72 3a _id: i32, owner:
0a70: 20 49 29 20 2d 3e 20 52 65 73 75 6c 74 3c 43 6f I) -> Result<Co
0a80: 77 3c 27 5f 2c 20 73 74 72 3e 3e 0a 09 77 68 65 w<'_, str>>..whe
0a90: 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 re I: Into<i64>
0aa0: 7b 0a 09 09 6d 61 74 63 68 20 73 71 6c 78 3a 3a {...match sqlx::
0ab0: 71 75 65 72 79 28 22 64 65 6c 65 74 65 20 66 72 query("delete fr
0ac0: 6f 6d 20 72 73 73 74 67 5f 73 6f 75 72 63 65 20 om rsstg_source
0ad0: 77 68 65 72 65 20 73 6f 75 72 63 65 5f 69 64 20 where source_id
0ae0: 3d 20 24 31 20 61 6e 64 20 6f 77 6e 65 72 20 3d = $1 and owner =
0af0: 20 24 32 3b 22 29 0a 09 09 09 2e 62 69 6e 64 28 $2;").....bind(
0b00: 73 6f 75 72 63 65 5f 69 64 29 0a 09 09 09 2e 62 source_id).....b
0b10: 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 ind(owner.into()
0b20: 29 0a 09 09 09 2e 65 78 65 63 75 74 65 28 26 6d ).....execute(&m
0b30: 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 ut *self.0).awai
0b40: 74 2e 73 74 61 63 6b 28 29 3f 2e 72 6f 77 73 5f t.stack()?.rows_
0b50: 61 66 66 65 63 74 65 64 28 29 20 7b 0a 09 09 09 affected() {....
0b60: 30 20 3d 3e 20 7b 20 4f 6b 28 22 4e 6f 20 64 61 0 => { Ok("No da
0b70: 74 61 20 66 6f 75 6e 64 20 66 6f 75 6e 64 2e 22 ta found found."
0b80: 2e 69 6e 74 6f 28 29 29 20 7d 2c 0a 09 09 09 78 .into()) },....x
0b90: 20 3d 3e 20 7b 20 4f 6b 28 66 6f 72 6d 61 74 21 => { Ok(format!
0ba0: 28 22 7b 78 7d 20 73 6f 75 72 63 65 73 20 72 65 ("{x} sources re
0bb0: 6d 6f 76 65 64 2e 22 29 2e 69 6e 74 6f 28 29 29 moved.").into())
0bc0: 20 7d 2c 0a 09 09 7d 0a 09 7d 0a 0a 09 70 75 62 },...}..}...pub
0bd0: 20 61 73 79 6e 63 20 66 6e 20 64 69 73 61 62 6c async fn disabl
0be0: 65 20 3c 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 e <I> (&mut self
0bf0: 2c 20 73 6f 75 72 63 65 5f 69 64 3a 20 69 33 32 , source_id: i32
0c00: 2c 20 6f 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 , owner: I) -> R
0c10: 65 73 75 6c 74 3c 26 73 74 72 3e 0a 09 77 68 65 esult<&str>..whe
0c20: 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 re I: Into<i64>
0c30: 7b 0a 09 09 6d 61 74 63 68 20 73 71 6c 78 3a 3a {...match sqlx::
0c40: 71 75 65 72 79 28 22 75 70 64 61 74 65 20 72 73 query("update rs
0c50: 73 74 67 5f 73 6f 75 72 63 65 20 73 65 74 20 65 stg_source set e
0c60: 6e 61 62 6c 65 64 20 3d 20 66 61 6c 73 65 20 77 nabled = false w
0c70: 68 65 72 65 20 73 6f 75 72 63 65 5f 69 64 20 3d here source_id =
0c80: 20 24 31 20 61 6e 64 20 6f 77 6e 65 72 20 3d 20 $1 and owner =
0c90: 24 32 22 29 0a 09 09 09 2e 62 69 6e 64 28 73 6f $2").....bind(so
0ca0: 75 72 63 65 5f 69 64 29 0a 09 09 09 2e 62 69 6e urce_id).....bin
0cb0: 64 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a d(owner.into()).
0cc0: 09 09 09 2e 65 78 65 63 75 74 65 28 26 6d 75 74 ....execute(&mut
0cd0: 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 2e *self.0).await.
0ce0: 73 74 61 63 6b 28 29 3f 2e 72 6f 77 73 5f 61 66 stack()?.rows_af
0cf0: 66 65 63 74 65 64 28 29 20 7b 0a 09 09 09 31 20 fected() {....1
0d00: 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 72 63 65 20 => { Ok("Source
0d10: 64 69 73 61 62 6c 65 64 2e 22 29 20 7d 2c 0a 09 disabled.") },..
0d20: 09 09 30 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 ..0 => { Ok("Sou
0d30: 72 63 65 20 6e 6f 74 20 66 6f 75 6e 64 2e 22 29 rce not found.")
0d40: 20 7d 2c 0a 09 09 09 5f 20 3d 3e 20 7b 20 62 61 },...._ => { ba
0d50: 69 6c 21 28 22 44 61 74 61 62 61 73 65 20 65 72 il!("Database er
0d60: 72 6f 72 2e 22 29 20 7d 2c 0a 09 09 7d 0a 09 7d ror.") },...}..}
0d70: 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 ...pub async fn
0d80: 65 6e 61 62 6c 65 20 3c 49 3e 20 28 26 6d 75 74 enable <I> (&mut
0d90: 20 73 65 6c 66 2c 20 73 6f 75 72 63 65 5f 69 64 self, source_id
0da0: 3a 20 69 33 32 2c 20 6f 77 6e 65 72 3a 20 49 29 : i32, owner: I)
0db0: 20 2d 3e 20 52 65 73 75 6c 74 3c 26 73 74 72 3e -> Result<&str>
0dc0: 0a 09 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c ..where I: Into<
0dd0: 69 36 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 73 i64> {...match s
0de0: 71 6c 78 3a 3a 71 75 65 72 79 28 22 75 70 64 61 qlx::query("upda
0df0: 74 65 20 72 73 73 74 67 5f 73 6f 75 72 63 65 20 te rsstg_source
0e00: 73 65 74 20 65 6e 61 62 6c 65 64 20 3d 20 74 72 set enabled = tr
0e10: 75 65 20 77 68 65 72 65 20 73 6f 75 72 63 65 5f ue where source_
0e20: 69 64 20 3d 20 24 31 20 61 6e 64 20 6f 77 6e 65 id = $1 and owne
0e30: 72 20 3d 20 24 32 22 29 0a 09 09 09 2e 62 69 6e r = $2").....bin
0e40: 64 28 73 6f 75 72 63 65 5f 69 64 29 0a 09 09 09 d(source_id)....
0e50: 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f .bind(owner.into
0e60: 28 29 29 0a 09 09 09 2e 65 78 65 63 75 74 65 28 ()).....execute(
0e70: 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 &mut *self.0).aw
0e80: 61 69 74 2e 73 74 61 63 6b 28 29 3f 2e 72 6f 77 ait.stack()?.row
0e90: 73 5f 61 66 66 65 63 74 65 64 28 29 20 7b 0a 09 s_affected() {..
0ea0: 09 09 31 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 ..1 => { Ok("Sou
0eb0: 72 63 65 20 65 6e 61 62 6c 65 64 2e 22 29 20 7d rce enabled.") }
0ec0: 2c 0a 09 09 09 30 20 3d 3e 20 7b 20 4f 6b 28 22 ,....0 => { Ok("
0ed0: 53 6f 75 72 63 65 20 6e 6f 74 20 66 6f 75 6e 64 Source not found
0ee0: 2e 22 29 20 7d 2c 0a 09 09 09 5f 20 3d 3e 20 7b .") },...._ => {
0ef0: 20 62 61 69 6c 21 28 22 44 61 74 61 62 61 73 65 bail!("Database
0f00: 20 65 72 72 6f 72 2e 22 29 20 7d 2c 0a 09 09 7d error.") },...}
0f10: 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 ..}...pub async
0f20: 66 6e 20 65 78 69 73 74 73 20 3c 49 3e 20 28 26 fn exists <I> (&
0f30: 6d 75 74 20 73 65 6c 66 2c 20 70 6f 73 74 5f 75 mut self, post_u
0f40: 72 6c 3a 20 26 73 74 72 2c 20 69 64 3a 20 49 29 rl: &str, id: I)
0f50: 20 2d 3e 20 52 65 73 75 6c 74 3c 4f 70 74 69 6f -> Result<Optio
0f60: 6e 3c 62 6f 6f 6c 3e 3e 0a 09 77 68 65 72 65 20 n<bool>>..where
0f70: 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 I: Into<i64> {..
0f80: 09 6c 65 74 20 72 6f 77 20 3d 20 73 71 6c 78 3a .let row = sqlx:
0f90: 3a 71 75 65 72 79 28 22 73 65 6c 65 63 74 20 65 :query("select e
0fa0: 78 69 73 74 73 28 73 65 6c 65 63 74 20 74 72 75 xists(select tru
0fb0: 65 20 66 72 6f 6d 20 72 73 73 74 67 5f 70 6f 73 e from rsstg_pos
0fc0: 74 20 77 68 65 72 65 20 75 72 6c 20 3d 20 24 31 t where url = $1
0fd0: 20 61 6e 64 20 73 6f 75 72 63 65 5f 69 64 20 3d and source_id =
0fe0: 20 24 32 29 20 61 73 20 65 78 69 73 74 73 3b 22 $2) as exists;"
0ff0: 29 0a 09 09 09 2e 62 69 6e 64 28 70 6f 73 74 5f ).....bind(post_
1000: 75 72 6c 29 0a 09 09 09 2e 62 69 6e 64 28 69 64 url).....bind(id
1010: 2e 69 6e 74 6f 28 29 29 0a 09 09 09 2e 66 65 74 .into()).....fet
1020: 63 68 5f 6f 6e 65 28 26 6d 75 74 20 2a 73 65 6c ch_one(&mut *sel
1030: 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 63 6b f.0).await.stack
1040: 28 29 3f 3b 0a 09 09 6c 65 74 20 65 78 69 73 74 ()?;...let exist
1050: 73 3a 20 4f 70 74 69 6f 6e 3c 62 6f 6f 6c 3e 20 s: Option<bool>
1060: 3d 20 72 6f 77 2e 74 72 79 5f 67 65 74 28 22 65 = row.try_get("e
1070: 78 69 73 74 73 22 29 2e 73 74 61 63 6b 28 29 3f xists").stack()?
1080: 3b 0a 09 09 4f 6b 28 65 78 69 73 74 73 29 0a 09 ;...Ok(exists)..
1090: 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e }...pub async fn
10a0: 20 67 65 74 5f 71 75 65 75 65 20 28 26 6d 75 74 get_queue (&mut
10b0: 20 73 65 6c 66 29 20 2d 3e 20 52 65 73 75 6c 74 self) -> Result
10c0: 3c 56 65 63 3c 51 75 65 75 65 3e 3e 20 7b 0a 09 <Vec<Queue>> {..
10d0: 09 6c 65 74 20 62 6c 6f 63 6b 3a 20 56 65 63 3c .let block: Vec<
10e0: 51 75 65 75 65 3e 20 3d 20 73 71 6c 78 3a 3a 71 Queue> = sqlx::q
10f0: 75 65 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 uery_as("select
1100: 73 6f 75 72 63 65 5f 69 64 2c 20 6e 65 78 74 5f source_id, next_
1110: 66 65 74 63 68 2c 20 6f 77 6e 65 72 2c 20 6c 61 fetch, owner, la
1120: 73 74 5f 73 63 72 61 70 65 20 66 72 6f 6d 20 72 st_scrape from r
1130: 73 73 74 67 5f 6f 72 64 65 72 20 6e 61 74 75 72 sstg_order natur
1140: 61 6c 20 6c 65 66 74 20 6a 6f 69 6e 20 72 73 73 al left join rss
1150: 74 67 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 tg_source where
1160: 6e 65 78 74 5f 66 65 74 63 68 20 3c 20 6e 6f 77 next_fetch < now
1170: 28 29 20 2b 20 69 6e 74 65 72 76 61 6c 20 27 31 () + interval '1
1180: 20 6d 69 6e 75 74 65 27 3b 22 29 0a 09 09 09 2e minute';").....
1190: 66 65 74 63 68 5f 61 6c 6c 28 26 6d 75 74 20 2a fetch_all(&mut *
11a0: 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 self.0).await.st
11b0: 61 63 6b 28 29 3f 3b 0a 09 09 4f 6b 28 62 6c 6f ack()?;...Ok(blo
11c0: 63 6b 29 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 ck)..}...pub asy
11d0: 6e 63 20 66 6e 20 67 65 74 5f 6c 69 73 74 20 3c nc fn get_list <
11e0: 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 6f I> (&mut self, o
11f0: 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 wner: I) -> Resu
1200: 6c 74 3c 56 65 63 3c 4c 69 73 74 3e 3e 0a 09 77 lt<Vec<List>>..w
1210: 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 here I: Into<i64
1220: 3e 20 7b 0a 09 09 6c 65 74 20 73 6f 75 72 63 65 > {...let source
1230: 3a 20 56 65 63 3c 4c 69 73 74 3e 20 3d 20 73 71 : Vec<List> = sq
1240: 6c 78 3a 3a 71 75 65 72 79 5f 61 73 28 22 73 65 lx::query_as("se
1250: 6c 65 63 74 20 73 6f 75 72 63 65 5f 69 64 2c 20 lect source_id,
1260: 63 68 61 6e 6e 65 6c 2c 20 65 6e 61 62 6c 65 64 channel, enabled
1270: 2c 20 75 72 6c 2c 20 69 76 5f 68 61 73 68 2c 20 , url, iv_hash,
1280: 75 72 6c 5f 72 65 20 66 72 6f 6d 20 72 73 73 74 url_re from rsst
1290: 67 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 6f g_source where o
12a0: 77 6e 65 72 20 3d 20 24 31 20 6f 72 64 65 72 20 wner = $1 order
12b0: 62 79 20 73 6f 75 72 63 65 5f 69 64 22 29 0a 09 by source_id")..
12c0: 09 09 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e ...bind(owner.in
12d0: 74 6f 28 29 29 0a 09 09 09 2e 66 65 74 63 68 5f to()).....fetch_
12e0: 61 6c 6c 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 all(&mut *self.0
12f0: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f ).await.stack()?
1300: 3b 0a 09 09 4f 6b 28 73 6f 75 72 63 65 29 0a 09 ;...Ok(source)..
1310: 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e }...pub async fn
1320: 20 67 65 74 5f 6f 6e 65 20 3c 49 3e 20 28 26 6d get_one <I> (&m
1330: 75 74 20 73 65 6c 66 2c 20 6f 77 6e 65 72 3a 20 ut self, owner:
1340: 49 2c 20 69 64 3a 20 69 33 32 29 20 2d 3e 20 52 I, id: i32) -> R
1350: 65 73 75 6c 74 3c 4f 70 74 69 6f 6e 3c 4c 69 73 esult<Option<Lis
1360: 74 3e 3e 0a 09 77 68 65 72 65 20 49 3a 20 49 6e t>>..where I: In
1370: 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c 65 74 20 to<i64> {...let
1380: 73 6f 75 72 63 65 3a 20 4f 70 74 69 6f 6e 3c 4c source: Option<L
1390: 69 73 74 3e 20 3d 20 73 71 6c 78 3a 3a 71 75 65 ist> = sqlx::que
13a0: 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 73 6f ry_as("select so
13b0: 75 72 63 65 5f 69 64 2c 20 63 68 61 6e 6e 65 6c urce_id, channel
13c0: 2c 20 65 6e 61 62 6c 65 64 2c 20 75 72 6c 2c 20 , enabled, url,
13d0: 69 76 5f 68 61 73 68 2c 20 75 72 6c 5f 72 65 20 iv_hash, url_re
13e0: 66 72 6f 6d 20 72 73 73 74 67 5f 73 6f 75 72 63 from rsstg_sourc
13f0: 65 20 77 68 65 72 65 20 6f 77 6e 65 72 20 3d 20 e where owner =
1400: 24 31 20 61 6e 64 20 73 6f 75 72 63 65 5f 69 64 $1 and source_id
1410: 20 3d 20 24 32 22 29 0a 09 09 09 2e 62 69 6e 64 = $2").....bind
1420: 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 (owner.into())..
1430: 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 09 2e ...bind(id).....
1440: 66 65 74 63 68 5f 6f 70 74 69 6f 6e 61 6c 28 26 fetch_optional(&
1450: 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 mut *self.0).awa
1460: 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 09 4f it.stack()?;...O
1470: 6b 28 73 6f 75 72 63 65 29 0a 09 7d 0a 0a 09 70 k(source)..}...p
1480: 75 62 20 61 73 79 6e 63 20 66 6e 20 67 65 74 5f ub async fn get_
1490: 73 6f 75 72 63 65 20 3c 49 3e 20 28 26 6d 75 74 source <I> (&mut
14a0: 20 73 65 6c 66 2c 20 69 64 3a 20 69 33 32 2c 20 self, id: i32,
14b0: 6f 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 owner: I) -> Res
14c0: 75 6c 74 3c 53 6f 75 72 63 65 3e 0a 09 77 68 65 ult<Source>..whe
14d0: 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 re I: Into<i64>
14e0: 7b 0a 09 09 6c 65 74 20 73 6f 75 72 63 65 3a 20 {...let source:
14f0: 53 6f 75 72 63 65 20 3d 20 73 71 6c 78 3a 3a 71 Source = sqlx::q
1500: 75 65 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 uery_as("select
1510: 63 68 61 6e 6e 65 6c 5f 69 64 2c 20 75 72 6c 2c channel_id, url,
1520: 20 69 76 5f 68 61 73 68 2c 20 6f 77 6e 65 72 2c iv_hash, owner,
1530: 20 75 72 6c 5f 72 65 20 66 72 6f 6d 20 72 73 73 url_re from rss
1540: 74 67 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 tg_source where
1550: 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 31 20 61 source_id = $1 a
1560: 6e 64 20 6f 77 6e 65 72 20 3d 20 24 32 22 29 0a nd owner = $2").
1570: 09 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 09 ....bind(id)....
1580: 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f .bind(owner.into
1590: 28 29 29 0a 09 09 09 2e 66 65 74 63 68 5f 6f 6e ()).....fetch_on
15a0: 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e e(&mut *self.0).
15b0: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a await.stack()?;.
15c0: 09 09 4f 6b 28 73 6f 75 72 63 65 29 0a 09 7d 0a ..Ok(source)..}.
15d0: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 73 ..pub async fn s
15e0: 65 74 5f 73 63 72 61 70 65 20 3c 49 3e 20 28 26 et_scrape <I> (&
15f0: 6d 75 74 20 73 65 6c 66 2c 20 69 64 3a 20 49 29 mut self, id: I)
1600: 20 2d 3e 20 52 65 73 75 6c 74 3c 28 29 3e 0a 09 -> Result<()>..
1610: 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 where I: Into<i6
1620: 34 3e 20 7b 0a 09 09 73 71 6c 78 3a 3a 71 75 65 4> {...sqlx::que
1630: 72 79 28 22 75 70 64 61 74 65 20 72 73 73 74 67 ry("update rsstg
1640: 5f 73 6f 75 72 63 65 20 73 65 74 20 6c 61 73 74 _source set last
1650: 5f 73 63 72 61 70 65 20 3d 20 6e 6f 77 28 29 20 _scrape = now()
1660: 77 68 65 72 65 20 73 6f 75 72 63 65 5f 69 64 20 where source_id
1670: 3d 20 24 31 3b 22 29 0a 09 09 09 2e 62 69 6e 64 = $1;").....bind
1680: 28 69 64 2e 69 6e 74 6f 28 29 29 0a 09 09 09 2e (id.into()).....
1690: 65 78 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 execute(&mut *se
16a0: 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 63 lf.0).await.stac
16b0: 6b 28 29 3f 3b 0a 09 09 4f 6b 28 28 29 29 0a 09 k()?;...Ok(())..
16c0: 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e }...pub async fn
16d0: 20 75 70 64 61 74 65 20 3c 49 3e 20 28 26 6d 75 update <I> (&mu
16e0: 74 20 73 65 6c 66 2c 20 75 70 64 61 74 65 3a 20 t self, update:
16f0: 4f 70 74 69 6f 6e 3c 69 33 32 3e 2c 20 63 68 61 Option<i32>, cha
1700: 6e 6e 65 6c 3a 20 26 73 74 72 2c 20 63 68 61 6e nnel: &str, chan
1710: 6e 65 6c 5f 69 64 3a 20 69 36 34 2c 20 75 72 6c nel_id: i64, url
1720: 3a 20 26 73 74 72 2c 20 69 76 5f 68 61 73 68 3a : &str, iv_hash:
1730: 20 4f 70 74 69 6f 6e 3c 26 73 74 72 3e 2c 20 75 Option<&str>, u
1740: 72 6c 5f 72 65 3a 20 4f 70 74 69 6f 6e 3c 26 73 rl_re: Option<&s
1750: 74 72 3e 2c 20 6f 77 6e 65 72 3a 20 49 29 20 2d tr>, owner: I) -
1760: 3e 20 52 65 73 75 6c 74 3c 26 73 74 72 3e 0a 09 > Result<&str>..
1770: 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 where I: Into<i6
1780: 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 6d 61 74 4> {...match mat
1790: 63 68 20 75 70 64 61 74 65 20 7b 0a 09 09 09 09 ch update {.....
17a0: 53 6f 6d 65 28 69 64 29 20 3d 3e 20 7b 0a 09 09 Some(id) => {...
17b0: 09 09 09 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 ...sqlx::query("
17c0: 75 70 64 61 74 65 20 72 73 73 74 67 5f 73 6f 75 update rsstg_sou
17d0: 72 63 65 20 73 65 74 20 63 68 61 6e 6e 65 6c 5f rce set channel_
17e0: 69 64 20 3d 20 24 32 2c 20 75 72 6c 20 3d 20 24 id = $2, url = $
17f0: 33 2c 20 69 76 5f 68 61 73 68 20 3d 20 24 34 2c 3, iv_hash = $4,
1800: 20 6f 77 6e 65 72 20 3d 20 24 35 2c 20 63 68 61 owner = $5, cha
1810: 6e 6e 65 6c 20 3d 20 24 36 2c 20 75 72 6c 5f 72 nnel = $6, url_r
1820: 65 20 3d 20 24 37 20 77 68 65 72 65 20 73 6f 75 e = $7 where sou
1830: 72 63 65 5f 69 64 20 3d 20 24 31 22 29 0a 09 09 rce_id = $1")...
1840: 09 09 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 .....bind(id)...
1850: 09 09 7d 2c 0a 09 09 09 09 4e 6f 6e 65 20 3d 3e ..},.....None =>
1860: 20 7b 0a 09 09 09 09 09 73 71 6c 78 3a 3a 71 75 {......sqlx::qu
1870: 65 72 79 28 22 69 6e 73 65 72 74 20 69 6e 74 6f ery("insert into
1880: 20 72 73 73 74 67 5f 73 6f 75 72 63 65 20 28 63 rsstg_source (c
1890: 68 61 6e 6e 65 6c 5f 69 64 2c 20 75 72 6c 2c 20 hannel_id, url,
18a0: 69 76 5f 68 61 73 68 2c 20 6f 77 6e 65 72 2c 20 iv_hash, owner,
18b0: 63 68 61 6e 6e 65 6c 2c 20 75 72 6c 5f 72 65 29 channel, url_re)
18c0: 20 76 61 6c 75 65 73 20 28 24 31 2c 20 24 32 2c values ($1, $2,
18d0: 20 24 33 2c 20 24 34 2c 20 24 35 2c 20 24 36 29 $3, $4, $5, $6)
18e0: 22 29 0a 09 09 09 09 7d 2c 0a 09 09 09 7d 0a 09 ").....},....}..
18f0: 09 09 09 2e 62 69 6e 64 28 63 68 61 6e 6e 65 6c ....bind(channel
1900: 5f 69 64 29 0a 09 09 09 09 2e 62 69 6e 64 28 75 _id)......bind(u
1910: 72 6c 29 0a 09 09 09 09 2e 62 69 6e 64 28 69 76 rl)......bind(iv
1920: 5f 68 61 73 68 29 0a 09 09 09 09 2e 62 69 6e 64 _hash)......bind
1930: 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 (owner.into())..
1940: 09 09 09 2e 62 69 6e 64 28 63 68 61 6e 6e 65 6c ....bind(channel
1950: 29 0a 09 09 09 09 2e 62 69 6e 64 28 75 72 6c 5f )......bind(url_
1960: 72 65 29 0a 09 09 09 09 2e 65 78 65 63 75 74 65 re)......execute
1970: 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 (&mut *self.0).a
1980: 77 61 69 74 0a 09 09 09 7b 0a 09 09 09 4f 6b 28 wait....{....Ok(
1990: 5f 29 20 3d 3e 20 4f 6b 28 6d 61 74 63 68 20 75 _) => Ok(match u
19a0: 70 64 61 74 65 20 7b 0a 09 09 09 09 53 6f 6d 65 pdate {.....Some
19b0: 28 5f 29 20 3d 3e 20 22 43 68 61 6e 6e 65 6c 20 (_) => "Channel
19c0: 75 70 64 61 74 65 64 2e 22 2c 0a 09 09 09 09 4e updated.",.....N
19d0: 6f 6e 65 20 3d 3e 20 22 43 68 61 6e 6e 65 6c 20 one => "Channel
19e0: 61 64 64 65 64 2e 22 2c 0a 09 09 09 7d 29 2c 0a added.",....}),.
19f0: 09 09 09 45 72 72 28 73 71 6c 78 3a 3a 45 72 72 ...Err(sqlx::Err
1a00: 6f 72 3a 3a 44 61 74 61 62 61 73 65 28 65 72 72 or::Database(err
1a10: 29 29 20 3d 3e 20 7b 0a 09 09 09 09 6d 61 74 63 )) => {.....matc
1a20: 68 20 65 72 72 2e 64 6f 77 6e 63 61 73 74 3a 3a h err.downcast::
1a30: 3c 73 71 6c 78 3a 3a 70 6f 73 74 67 72 65 73 3a <sqlx::postgres:
1a40: 3a 50 67 44 61 74 61 62 61 73 65 45 72 72 6f 72 :PgDatabaseError
1a50: 3e 28 29 2e 72 6f 75 74 69 6e 65 28 29 20 7b 0a >().routine() {.
1a60: 09 09 09 09 09 53 6f 6d 65 28 22 5f 62 74 5f 63 .....Some("_bt_c
1a70: 68 65 63 6b 5f 75 6e 69 71 75 65 22 2c 20 29 20 heck_unique", )
1a80: 3d 3e 20 7b 0a 09 09 09 09 09 09 4f 6b 28 22 44 => {.......Ok("D
1a90: 75 70 6c 69 63 61 74 65 20 6b 65 79 2e 22 29 0a uplicate key.").
1aa0: 09 09 09 09 09 7d 2c 0a 09 09 09 09 09 53 6f 6d .....},......Som
1ab0: 65 28 5f 29 20 3d 3e 20 7b 0a 09 09 09 09 09 09 e(_) => {.......
1ac0: 4f 6b 28 22 44 61 74 61 62 61 73 65 20 65 72 72 Ok("Database err
1ad0: 6f 72 2e 22 29 0a 09 09 09 09 09 7d 2c 0a 09 09 or.")......},...
1ae0: 09 09 09 4e 6f 6e 65 20 3d 3e 20 7b 0a 09 09 09 ...None => {....
1af0: 09 09 09 4f 6b 28 22 4e 6f 20 64 61 74 61 62 61 ...Ok("No databa
1b00: 73 65 20 65 72 72 6f 72 20 65 78 74 72 61 63 74 se error extract
1b10: 65 64 2e 22 29 0a 09 09 09 09 09 7d 2c 0a 09 09 ed.")......},...
1b20: 09 09 7d 0a 09 09 09 7d 2c 0a 09 09 09 45 72 72 ..}....},....Err
1b30: 28 65 72 72 29 20 3d 3e 20 7b 0a 09 09 09 09 62 (err) => {.....b
1b40: 61 69 6c 21 28 22 53 6f 72 72 79 2c 20 75 6e 6b ail!("Sorry, unk
1b50: 6e 6f 77 6e 20 65 72 72 6f 72 3a 5c 6e 7b 65 72 nown error:\n{er
1b60: 72 3a 23 3f 7d 5c 6e 22 29 3b 0a 09 09 09 7d 2c r:#?}\n");....},
1b70: 0a 09 09 7d 0a 09 7d 0a 7d 0a ...}..}.}.