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: 7d 0a 0a 23 5b 64 65 72 69 76 65 28 43 6c 6f 6e }..#[derive(Clon
04e0: 65 29 5d 0a 70 75 62 20 73 74 72 75 63 74 20 44 e)].pub struct D
04f0: 62 20 28 0a 09 41 72 63 3c 4d 75 74 65 78 3c 73 b (..Arc<Mutex<s
0500: 71 6c 78 3a 3a 50 6f 6f 6c 3c 73 71 6c 78 3a 3a qlx::Pool<sqlx::
0510: 50 6f 73 74 67 72 65 73 3e 3e 3e 2c 0a 29 3b 0a Postgres>>>,.);.
0520: 0a 69 6d 70 6c 20 44 62 20 7b 0a 09 70 75 62 20 .impl Db {..pub
0530: 66 6e 20 6e 65 77 20 28 70 67 75 72 69 3a 20 26 fn new (pguri: &
0540: 73 74 72 29 20 2d 3e 20 52 65 73 75 6c 74 3c 44 str) -> Result<D
0550: 62 3e 20 7b 0a 09 09 4f 6b 28 44 62 20 28 0a 09 b> {...Ok(Db (..
0560: 09 09 41 72 63 3a 3a 6e 65 77 28 4d 75 74 65 78 ..Arc::new(Mutex
0570: 3a 3a 6e 65 77 28 50 67 50 6f 6f 6c 4f 70 74 69 ::new(PgPoolOpti
0580: 6f 6e 73 3a 3a 6e 65 77 28 29 0a 09 09 09 09 2e ons::new()......
0590: 6d 61 78 5f 63 6f 6e 6e 65 63 74 69 6f 6e 73 28 max_connections(
05a0: 35 29 0a 09 09 09 09 2e 61 63 71 75 69 72 65 5f 5)......acquire_
05b0: 74 69 6d 65 6f 75 74 28 73 74 64 3a 3a 74 69 6d timeout(std::tim
05c0: 65 3a 3a 44 75 72 61 74 69 6f 6e 3a 3a 6e 65 77 e::Duration::new
05d0: 28 33 30 30 2c 20 30 29 29 0a 09 09 09 09 2e 69 (300, 0))......i
05e0: 64 6c 65 5f 74 69 6d 65 6f 75 74 28 73 74 64 3a dle_timeout(std:
05f0: 3a 74 69 6d 65 3a 3a 44 75 72 61 74 69 6f 6e 3a :time::Duration:
0600: 3a 6e 65 77 28 36 30 2c 20 30 29 29 0a 09 09 09 :new(60, 0))....
0610: 09 2e 63 6f 6e 6e 65 63 74 5f 6c 61 7a 79 28 70 ..connect_lazy(p
0620: 67 75 72 69 29 0a 09 09 09 09 2e 73 74 61 63 6b guri)......stack
0630: 28 29 3f 29 29 2c 0a 09 09 29 29 0a 09 7d 0a 0a ()?)),...))..}..
0640: 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 62 65 .pub async fn be
0650: 67 69 6e 28 26 73 65 6c 66 29 20 2d 3e 20 52 65 gin(&self) -> Re
0660: 73 75 6c 74 3c 43 6f 6e 6e 3e 20 7b 0a 09 09 6c sult<Conn> {...l
0670: 65 74 20 70 6f 6f 6c 20 3d 20 73 65 6c 66 2e 30 et pool = self.0
0680: 2e 6c 6f 63 6b 5f 61 72 63 28 29 2e 61 77 61 69 .lock_arc().awai
0690: 74 3b 0a 09 09 6c 65 74 20 63 6f 6e 6e 20 3d 20 t;...let conn =
06a0: 43 6f 6e 6e 20 28 20 70 6f 6f 6c 2e 61 63 71 75 Conn ( pool.acqu
06b0: 69 72 65 28 29 2e 61 77 61 69 74 2e 73 74 61 63 ire().await.stac
06c0: 6b 28 29 3f 20 29 3b 0a 09 09 4f 6b 28 63 6f 6e k()? );...Ok(con
06d0: 6e 29 0a 09 7d 0a 7d 0a 0a 70 75 62 20 73 74 72 n)..}.}..pub str
06e0: 75 63 74 20 43 6f 6e 6e 20 28 0a 09 50 6f 6f 6c uct Conn (..Pool
06f0: 43 6f 6e 6e 65 63 74 69 6f 6e 3c 50 6f 73 74 67 Connection<Postg
0700: 72 65 73 3e 2c 0a 29 3b 0a 0a 69 6d 70 6c 20 43 res>,.);..impl C
0710: 6f 6e 6e 20 7b 0a 09 70 75 62 20 61 73 79 6e 63 onn {..pub async
0720: 20 66 6e 20 61 64 64 5f 70 6f 73 74 20 28 26 6d fn add_post (&m
0730: 75 74 20 73 65 6c 66 2c 20 73 6f 75 72 63 65 5f ut self, source_
0740: 69 64 3a 20 69 33 32 2c 20 64 61 74 65 3a 20 26 id: i32, date: &
0750: 44 61 74 65 54 69 6d 65 3c 46 69 78 65 64 4f 66 DateTime<FixedOf
0760: 66 73 65 74 3e 2c 20 70 6f 73 74 5f 75 72 6c 3a fset>, post_url:
0770: 20 26 73 74 72 29 20 2d 3e 20 52 65 73 75 6c 74 &str) -> Result
0780: 3c 28 29 3e 20 7b 0a 09 09 73 71 6c 78 3a 3a 71 <()> {...sqlx::q
0790: 75 65 72 79 28 22 69 6e 73 65 72 74 20 69 6e 74 uery("insert int
07a0: 6f 20 72 73 73 74 67 5f 70 6f 73 74 20 28 73 6f o rsstg_post (so
07b0: 75 72 63 65 5f 69 64 2c 20 70 6f 73 74 65 64 2c urce_id, posted,
07c0: 20 75 72 6c 29 20 76 61 6c 75 65 73 20 28 24 31 url) values ($1
07d0: 2c 20 24 32 2c 20 24 33 29 3b 22 29 0a 09 09 09 , $2, $3);")....
07e0: 2e 62 69 6e 64 28 73 6f 75 72 63 65 5f 69 64 29 .bind(source_id)
07f0: 0a 09 09 09 2e 62 69 6e 64 28 64 61 74 65 29 0a .....bind(date).
0800: 09 09 09 2e 62 69 6e 64 28 70 6f 73 74 5f 75 72 ....bind(post_ur
0810: 6c 29 0a 09 09 09 2e 65 78 65 63 75 74 65 28 26 l).....execute(&
0820: 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 mut *self.0).awa
0830: 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 09 4f it.stack()?;...O
0840: 6b 28 28 29 29 0a 09 7d 0a 0a 09 70 75 62 20 61 k(())..}...pub a
0850: 73 79 6e 63 20 66 6e 20 63 6c 65 61 6e 20 3c 49 sync fn clean <I
0860: 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 73 6f > (&mut self, so
0870: 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 20 6f 77 urce_id: i32, ow
0880: 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c ner: I) -> Resul
0890: 74 3c 43 6f 77 3c 27 5f 2c 20 73 74 72 3e 3e 0a t<Cow<'_, str>>.
08a0: 09 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 .where I: Into<i
08b0: 36 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 73 71 64> {...match sq
08c0: 6c 78 3a 3a 71 75 65 72 79 28 22 64 65 6c 65 74 lx::query("delet
08d0: 65 20 66 72 6f 6d 20 72 73 73 74 67 5f 70 6f 73 e from rsstg_pos
08e0: 74 20 70 20 75 73 69 6e 67 20 72 73 73 74 67 5f t p using rsstg_
08f0: 73 6f 75 72 63 65 20 73 20 77 68 65 72 65 20 70 source s where p
0900: 2e 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 31 20 .source_id = $1
0910: 61 6e 64 20 6f 77 6e 65 72 20 3d 20 24 32 20 61 and owner = $2 a
0920: 6e 64 20 70 2e 73 6f 75 72 63 65 5f 69 64 20 3d nd p.source_id =
0930: 20 73 2e 73 6f 75 72 63 65 5f 69 64 3b 22 29 0a s.source_id;").
0940: 09 09 09 2e 62 69 6e 64 28 73 6f 75 72 63 65 5f ....bind(source_
0950: 69 64 29 0a 09 09 09 2e 62 69 6e 64 28 6f 77 6e id).....bind(own
0960: 65 72 2e 69 6e 74 6f 28 29 29 0a 09 09 09 2e 65 er.into()).....e
0970: 78 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 6c xecute(&mut *sel
0980: 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 63 6b f.0).await.stack
0990: 28 29 3f 2e 72 6f 77 73 5f 61 66 66 65 63 74 65 ()?.rows_affecte
09a0: 64 28 29 20 7b 0a 09 09 09 30 20 3d 3e 20 7b 20 d() {....0 => {
09b0: 4f 6b 28 22 4e 6f 20 64 61 74 61 20 66 6f 75 6e Ok("No data foun
09c0: 64 20 66 6f 75 6e 64 2e 22 2e 69 6e 74 6f 28 29 d found.".into()
09d0: 29 20 7d 2c 0a 09 09 09 78 20 3d 3e 20 7b 20 4f ) },....x => { O
09e0: 6b 28 66 6f 72 6d 61 74 21 28 22 7b 78 7d 20 70 k(format!("{x} p
09f0: 6f 73 74 73 20 70 75 72 67 65 64 2e 22 29 2e 69 osts purged.").i
0a00: 6e 74 6f 28 29 29 20 7d 2c 0a 09 09 7d 0a 09 7d nto()) },...}..}
0a10: 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 ...pub async fn
0a20: 64 65 6c 65 74 65 20 3c 49 3e 20 28 26 6d 75 74 delete <I> (&mut
0a30: 20 73 65 6c 66 2c 20 73 6f 75 72 63 65 5f 69 64 self, source_id
0a40: 3a 20 69 33 32 2c 20 6f 77 6e 65 72 3a 20 49 29 : i32, owner: I)
0a50: 20 2d 3e 20 52 65 73 75 6c 74 3c 43 6f 77 3c 27 -> Result<Cow<'
0a60: 5f 2c 20 73 74 72 3e 3e 0a 09 77 68 65 72 65 20 _, str>>..where
0a70: 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 I: Into<i64> {..
0a80: 09 6d 61 74 63 68 20 73 71 6c 78 3a 3a 71 75 65 .match sqlx::que
0a90: 72 79 28 22 64 65 6c 65 74 65 20 66 72 6f 6d 20 ry("delete from
0aa0: 72 73 73 74 67 5f 73 6f 75 72 63 65 20 77 68 65 rsstg_source whe
0ab0: 72 65 20 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 re source_id = $
0ac0: 31 20 61 6e 64 20 6f 77 6e 65 72 20 3d 20 24 32 1 and owner = $2
0ad0: 3b 22 29 0a 09 09 09 2e 62 69 6e 64 28 73 6f 75 ;").....bind(sou
0ae0: 72 63 65 5f 69 64 29 0a 09 09 09 2e 62 69 6e 64 rce_id).....bind
0af0: 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 (owner.into())..
0b00: 09 09 2e 65 78 65 63 75 74 65 28 26 6d 75 74 20 ...execute(&mut
0b10: 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 *self.0).await.s
0b20: 74 61 63 6b 28 29 3f 2e 72 6f 77 73 5f 61 66 66 tack()?.rows_aff
0b30: 65 63 74 65 64 28 29 20 7b 0a 09 09 09 30 20 3d ected() {....0 =
0b40: 3e 20 7b 20 4f 6b 28 22 4e 6f 20 64 61 74 61 20 > { Ok("No data
0b50: 66 6f 75 6e 64 20 66 6f 75 6e 64 2e 22 2e 69 6e found found.".in
0b60: 74 6f 28 29 29 20 7d 2c 0a 09 09 09 78 20 3d 3e to()) },....x =>
0b70: 20 7b 20 4f 6b 28 66 6f 72 6d 61 74 21 28 22 7b { Ok(format!("{
0b80: 78 7d 20 73 6f 75 72 63 65 73 20 72 65 6d 6f 76 x} sources remov
0b90: 65 64 2e 22 29 2e 69 6e 74 6f 28 29 29 20 7d 2c ed.").into()) },
0ba0: 0a 09 09 7d 0a 09 7d 0a 0a 09 70 75 62 20 61 73 ...}..}...pub as
0bb0: 79 6e 63 20 66 6e 20 64 69 73 61 62 6c 65 20 3c ync fn disable <
0bc0: 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 73 I> (&mut self, s
0bd0: 6f 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 20 6f ource_id: i32, o
0be0: 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 wner: I) -> Resu
0bf0: 6c 74 3c 26 73 74 72 3e 0a 09 77 68 65 72 65 20 lt<&str>..where
0c00: 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 I: Into<i64> {..
0c10: 09 6d 61 74 63 68 20 73 71 6c 78 3a 3a 71 75 65 .match sqlx::que
0c20: 72 79 28 22 75 70 64 61 74 65 20 72 73 73 74 67 ry("update rsstg
0c30: 5f 73 6f 75 72 63 65 20 73 65 74 20 65 6e 61 62 _source set enab
0c40: 6c 65 64 20 3d 20 66 61 6c 73 65 20 77 68 65 72 led = false wher
0c50: 65 20 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 31 e source_id = $1
0c60: 20 61 6e 64 20 6f 77 6e 65 72 20 3d 20 24 32 22 and owner = $2"
0c70: 29 0a 09 09 09 2e 62 69 6e 64 28 73 6f 75 72 63 ).....bind(sourc
0c80: 65 5f 69 64 29 0a 09 09 09 2e 62 69 6e 64 28 6f e_id).....bind(o
0c90: 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 09 09 wner.into())....
0ca0: 2e 65 78 65 63 75 74 65 28 26 6d 75 74 20 2a 73 .execute(&mut *s
0cb0: 65 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 elf.0).await.sta
0cc0: 63 6b 28 29 3f 2e 72 6f 77 73 5f 61 66 66 65 63 ck()?.rows_affec
0cd0: 74 65 64 28 29 20 7b 0a 09 09 09 31 20 3d 3e 20 ted() {....1 =>
0ce0: 7b 20 4f 6b 28 22 53 6f 75 72 63 65 20 64 69 73 { Ok("Source dis
0cf0: 61 62 6c 65 64 2e 22 29 20 7d 2c 0a 09 09 09 30 abled.") },....0
0d00: 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 72 63 65 => { Ok("Source
0d10: 20 6e 6f 74 20 66 6f 75 6e 64 2e 22 29 20 7d 2c not found.") },
0d20: 0a 09 09 09 5f 20 3d 3e 20 7b 20 62 61 69 6c 21 ...._ => { bail!
0d30: 28 22 44 61 74 61 62 61 73 65 20 65 72 72 6f 72 ("Database error
0d40: 2e 22 29 20 7d 2c 0a 09 09 7d 0a 09 7d 0a 0a 09 .") },...}..}...
0d50: 70 75 62 20 61 73 79 6e 63 20 66 6e 20 65 6e 61 pub async fn ena
0d60: 62 6c 65 20 3c 49 3e 20 28 26 6d 75 74 20 73 65 ble <I> (&mut se
0d70: 6c 66 2c 20 73 6f 75 72 63 65 5f 69 64 3a 20 69 lf, source_id: i
0d80: 33 32 2c 20 6f 77 6e 65 72 3a 20 49 29 20 2d 3e 32, owner: I) ->
0d90: 20 52 65 73 75 6c 74 3c 26 73 74 72 3e 0a 09 77 Result<&str>..w
0da0: 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 here I: Into<i64
0db0: 3e 20 7b 0a 09 09 6d 61 74 63 68 20 73 71 6c 78 > {...match sqlx
0dc0: 3a 3a 71 75 65 72 79 28 22 75 70 64 61 74 65 20 ::query("update
0dd0: 72 73 73 74 67 5f 73 6f 75 72 63 65 20 73 65 74 rsstg_source set
0de0: 20 65 6e 61 62 6c 65 64 20 3d 20 74 72 75 65 20 enabled = true
0df0: 77 68 65 72 65 20 73 6f 75 72 63 65 5f 69 64 20 where source_id
0e00: 3d 20 24 31 20 61 6e 64 20 6f 77 6e 65 72 20 3d = $1 and owner =
0e10: 20 24 32 22 29 0a 09 09 09 2e 62 69 6e 64 28 73 $2").....bind(s
0e20: 6f 75 72 63 65 5f 69 64 29 0a 09 09 09 2e 62 69 ource_id).....bi
0e30: 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 nd(owner.into())
0e40: 0a 09 09 09 2e 65 78 65 63 75 74 65 28 26 6d 75 .....execute(&mu
0e50: 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 t *self.0).await
0e60: 2e 73 74 61 63 6b 28 29 3f 2e 72 6f 77 73 5f 61 .stack()?.rows_a
0e70: 66 66 65 63 74 65 64 28 29 20 7b 0a 09 09 09 31 ffected() {....1
0e80: 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 72 63 65 => { Ok("Source
0e90: 20 65 6e 61 62 6c 65 64 2e 22 29 20 7d 2c 0a 09 enabled.") },..
0ea0: 09 09 30 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 ..0 => { Ok("Sou
0eb0: 72 63 65 20 6e 6f 74 20 66 6f 75 6e 64 2e 22 29 rce not found.")
0ec0: 20 7d 2c 0a 09 09 09 5f 20 3d 3e 20 7b 20 62 61 },...._ => { ba
0ed0: 69 6c 21 28 22 44 61 74 61 62 61 73 65 20 65 72 il!("Database er
0ee0: 72 6f 72 2e 22 29 20 7d 2c 0a 09 09 7d 0a 09 7d ror.") },...}..}
0ef0: 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 ...pub async fn
0f00: 65 78 69 73 74 73 20 3c 49 3e 20 28 26 6d 75 74 exists <I> (&mut
0f10: 20 73 65 6c 66 2c 20 70 6f 73 74 5f 75 72 6c 3a self, post_url:
0f20: 20 26 73 74 72 2c 20 69 64 3a 20 49 29 20 2d 3e &str, id: I) ->
0f30: 20 52 65 73 75 6c 74 3c 4f 70 74 69 6f 6e 3c 62 Result<Option<b
0f40: 6f 6f 6c 3e 3e 0a 09 77 68 65 72 65 20 49 3a 20 ool>>..where I:
0f50: 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c 65 Into<i64> {...le
0f60: 74 20 72 6f 77 20 3d 20 73 71 6c 78 3a 3a 71 75 t row = sqlx::qu
0f70: 65 72 79 28 22 73 65 6c 65 63 74 20 65 78 69 73 ery("select exis
0f80: 74 73 28 73 65 6c 65 63 74 20 74 72 75 65 20 66 ts(select true f
0f90: 72 6f 6d 20 72 73 73 74 67 5f 70 6f 73 74 20 77 rom rsstg_post w
0fa0: 68 65 72 65 20 75 72 6c 20 3d 20 24 31 20 61 6e here url = $1 an
0fb0: 64 20 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 32 d source_id = $2
0fc0: 29 20 61 73 20 65 78 69 73 74 73 3b 22 29 0a 09 ) as exists;")..
0fd0: 09 09 2e 62 69 6e 64 28 70 6f 73 74 5f 75 72 6c ...bind(post_url
0fe0: 29 0a 09 09 09 2e 62 69 6e 64 28 69 64 2e 69 6e ).....bind(id.in
0ff0: 74 6f 28 29 29 0a 09 09 09 2e 66 65 74 63 68 5f to()).....fetch_
1000: 6f 6e 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 one(&mut *self.0
1010: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f ).await.stack()?
1020: 3b 0a 09 09 6c 65 74 20 65 78 69 73 74 73 3a 20 ;...let exists:
1030: 4f 70 74 69 6f 6e 3c 62 6f 6f 6c 3e 20 3d 20 72 Option<bool> = r
1040: 6f 77 2e 74 72 79 5f 67 65 74 28 22 65 78 69 73 ow.try_get("exis
1050: 74 73 22 29 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 ts").stack()?;..
1060: 09 4f 6b 28 65 78 69 73 74 73 29 0a 09 7d 0a 0a .Ok(exists)..}..
1070: 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 67 65 .pub async fn ge
1080: 74 5f 71 75 65 75 65 20 28 26 6d 75 74 20 73 65 t_queue (&mut se
1090: 6c 66 29 20 2d 3e 20 52 65 73 75 6c 74 3c 56 65 lf) -> Result<Ve
10a0: 63 3c 51 75 65 75 65 3e 3e 20 7b 0a 09 09 6c 65 c<Queue>> {...le
10b0: 74 20 62 6c 6f 63 6b 3a 20 56 65 63 3c 51 75 65 t block: Vec<Que
10c0: 75 65 3e 20 3d 20 73 71 6c 78 3a 3a 71 75 65 72 ue> = sqlx::quer
10d0: 79 5f 61 73 28 22 73 65 6c 65 63 74 20 73 6f 75 y_as("select sou
10e0: 72 63 65 5f 69 64 2c 20 6e 65 78 74 5f 66 65 74 rce_id, next_fet
10f0: 63 68 2c 20 6f 77 6e 65 72 20 66 72 6f 6d 20 72 ch, owner from r
1100: 73 73 74 67 5f 6f 72 64 65 72 20 6e 61 74 75 72 sstg_order natur
1110: 61 6c 20 6c 65 66 74 20 6a 6f 69 6e 20 72 73 73 al left join rss
1120: 74 67 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 tg_source where
1130: 6e 65 78 74 5f 66 65 74 63 68 20 3c 20 6e 6f 77 next_fetch < now
1140: 28 29 20 2b 20 69 6e 74 65 72 76 61 6c 20 27 31 () + interval '1
1150: 20 6d 69 6e 75 74 65 27 3b 22 29 0a 09 09 09 2e minute';").....
1160: 66 65 74 63 68 5f 61 6c 6c 28 26 6d 75 74 20 2a fetch_all(&mut *
1170: 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 self.0).await.st
1180: 61 63 6b 28 29 3f 3b 0a 09 09 4f 6b 28 62 6c 6f ack()?;...Ok(blo
1190: 63 6b 29 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 ck)..}...pub asy
11a0: 6e 63 20 66 6e 20 67 65 74 5f 6c 69 73 74 20 3c nc fn get_list <
11b0: 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 6f I> (&mut self, o
11c0: 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 wner: I) -> Resu
11d0: 6c 74 3c 56 65 63 3c 4c 69 73 74 3e 3e 0a 09 77 lt<Vec<List>>..w
11e0: 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 here I: Into<i64
11f0: 3e 20 7b 0a 09 09 6c 65 74 20 73 6f 75 72 63 65 > {...let source
1200: 3a 20 56 65 63 3c 4c 69 73 74 3e 20 3d 20 73 71 : Vec<List> = sq
1210: 6c 78 3a 3a 71 75 65 72 79 5f 61 73 28 22 73 65 lx::query_as("se
1220: 6c 65 63 74 20 73 6f 75 72 63 65 5f 69 64 2c 20 lect source_id,
1230: 63 68 61 6e 6e 65 6c 2c 20 65 6e 61 62 6c 65 64 channel, enabled
1240: 2c 20 75 72 6c 2c 20 69 76 5f 68 61 73 68 2c 20 , url, iv_hash,
1250: 75 72 6c 5f 72 65 20 66 72 6f 6d 20 72 73 73 74 url_re from rsst
1260: 67 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 6f g_source where o
1270: 77 6e 65 72 20 3d 20 24 31 20 6f 72 64 65 72 20 wner = $1 order
1280: 62 79 20 73 6f 75 72 63 65 5f 69 64 22 29 0a 09 by source_id")..
1290: 09 09 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e ...bind(owner.in
12a0: 74 6f 28 29 29 0a 09 09 09 2e 66 65 74 63 68 5f to()).....fetch_
12b0: 61 6c 6c 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 all(&mut *self.0
12c0: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f ).await.stack()?
12d0: 3b 0a 09 09 4f 6b 28 73 6f 75 72 63 65 29 0a 09 ;...Ok(source)..
12e0: 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e }...pub async fn
12f0: 20 67 65 74 5f 6f 6e 65 20 3c 49 3e 20 28 26 6d get_one <I> (&m
1300: 75 74 20 73 65 6c 66 2c 20 6f 77 6e 65 72 3a 20 ut self, owner:
1310: 49 2c 20 69 64 3a 20 69 33 32 29 20 2d 3e 20 52 I, id: i32) -> R
1320: 65 73 75 6c 74 3c 4f 70 74 69 6f 6e 3c 4c 69 73 esult<Option<Lis
1330: 74 3e 3e 0a 09 77 68 65 72 65 20 49 3a 20 49 6e t>>..where I: In
1340: 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c 65 74 20 to<i64> {...let
1350: 73 6f 75 72 63 65 3a 20 4f 70 74 69 6f 6e 3c 4c source: Option<L
1360: 69 73 74 3e 20 3d 20 73 71 6c 78 3a 3a 71 75 65 ist> = sqlx::que
1370: 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 73 6f ry_as("select so
1380: 75 72 63 65 5f 69 64 2c 20 63 68 61 6e 6e 65 6c urce_id, channel
1390: 2c 20 65 6e 61 62 6c 65 64 2c 20 75 72 6c 2c 20 , enabled, url,
13a0: 69 76 5f 68 61 73 68 2c 20 75 72 6c 5f 72 65 20 iv_hash, url_re
13b0: 66 72 6f 6d 20 72 73 73 74 67 5f 73 6f 75 72 63 from rsstg_sourc
13c0: 65 20 77 68 65 72 65 20 6f 77 6e 65 72 20 3d 20 e where owner =
13d0: 24 31 20 61 6e 64 20 73 6f 75 72 63 65 5f 69 64 $1 and source_id
13e0: 20 3d 20 24 32 22 29 0a 09 09 09 2e 62 69 6e 64 = $2").....bind
13f0: 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 (owner.into())..
1400: 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 09 2e ...bind(id).....
1410: 66 65 74 63 68 5f 6f 70 74 69 6f 6e 61 6c 28 26 fetch_optional(&
1420: 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 mut *self.0).awa
1430: 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 09 4f it.stack()?;...O
1440: 6b 28 73 6f 75 72 63 65 29 0a 09 7d 0a 0a 09 70 k(source)..}...p
1450: 75 62 20 61 73 79 6e 63 20 66 6e 20 67 65 74 5f ub async fn get_
1460: 73 6f 75 72 63 65 20 3c 49 3e 20 28 26 6d 75 74 source <I> (&mut
1470: 20 73 65 6c 66 2c 20 69 64 3a 20 69 33 32 2c 20 self, id: i32,
1480: 6f 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 owner: I) -> Res
1490: 75 6c 74 3c 53 6f 75 72 63 65 3e 0a 09 77 68 65 ult<Source>..whe
14a0: 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 re I: Into<i64>
14b0: 7b 0a 09 09 6c 65 74 20 73 6f 75 72 63 65 3a 20 {...let source:
14c0: 53 6f 75 72 63 65 20 3d 20 73 71 6c 78 3a 3a 71 Source = sqlx::q
14d0: 75 65 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 uery_as("select
14e0: 63 68 61 6e 6e 65 6c 5f 69 64 2c 20 75 72 6c 2c channel_id, url,
14f0: 20 69 76 5f 68 61 73 68 2c 20 6f 77 6e 65 72 2c iv_hash, owner,
1500: 20 75 72 6c 5f 72 65 20 66 72 6f 6d 20 72 73 73 url_re from rss
1510: 74 67 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 tg_source where
1520: 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 31 20 61 source_id = $1 a
1530: 6e 64 20 6f 77 6e 65 72 20 3d 20 24 32 22 29 0a nd owner = $2").
1540: 09 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 09 ....bind(id)....
1550: 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f .bind(owner.into
1560: 28 29 29 0a 09 09 09 2e 66 65 74 63 68 5f 6f 6e ()).....fetch_on
1570: 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e e(&mut *self.0).
1580: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a await.stack()?;.
1590: 09 09 4f 6b 28 73 6f 75 72 63 65 29 0a 09 7d 0a ..Ok(source)..}.
15a0: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 73 ..pub async fn s
15b0: 65 74 5f 73 63 72 61 70 65 20 3c 49 3e 20 28 26 et_scrape <I> (&
15c0: 6d 75 74 20 73 65 6c 66 2c 20 69 64 3a 20 49 29 mut self, id: I)
15d0: 20 2d 3e 20 52 65 73 75 6c 74 3c 28 29 3e 0a 09 -> Result<()>..
15e0: 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 where I: Into<i6
15f0: 34 3e 20 7b 0a 09 09 73 71 6c 78 3a 3a 71 75 65 4> {...sqlx::que
1600: 72 79 28 22 75 70 64 61 74 65 20 72 73 73 74 67 ry("update rsstg
1610: 5f 73 6f 75 72 63 65 20 73 65 74 20 6c 61 73 74 _source set last
1620: 5f 73 63 72 61 70 65 20 3d 20 6e 6f 77 28 29 20 _scrape = now()
1630: 77 68 65 72 65 20 73 6f 75 72 63 65 5f 69 64 20 where source_id
1640: 3d 20 24 31 3b 22 29 0a 09 09 09 2e 62 69 6e 64 = $1;").....bind
1650: 28 69 64 2e 69 6e 74 6f 28 29 29 0a 09 09 09 2e (id.into()).....
1660: 65 78 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 execute(&mut *se
1670: 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 63 lf.0).await.stac
1680: 6b 28 29 3f 3b 0a 09 09 4f 6b 28 28 29 29 0a 09 k()?;...Ok(())..
1690: 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e }...pub async fn
16a0: 20 75 70 64 61 74 65 20 3c 49 3e 20 28 26 6d 75 update <I> (&mu
16b0: 74 20 73 65 6c 66 2c 20 75 70 64 61 74 65 3a 20 t self, update:
16c0: 4f 70 74 69 6f 6e 3c 69 33 32 3e 2c 20 63 68 61 Option<i32>, cha
16d0: 6e 6e 65 6c 3a 20 26 73 74 72 2c 20 63 68 61 6e nnel: &str, chan
16e0: 6e 65 6c 5f 69 64 3a 20 69 36 34 2c 20 75 72 6c nel_id: i64, url
16f0: 3a 20 26 73 74 72 2c 20 69 76 5f 68 61 73 68 3a : &str, iv_hash:
1700: 20 4f 70 74 69 6f 6e 3c 26 73 74 72 3e 2c 20 75 Option<&str>, u
1710: 72 6c 5f 72 65 3a 20 4f 70 74 69 6f 6e 3c 26 73 rl_re: Option<&s
1720: 74 72 3e 2c 20 6f 77 6e 65 72 3a 20 49 29 20 2d tr>, owner: I) -
1730: 3e 20 52 65 73 75 6c 74 3c 26 73 74 72 3e 0a 09 > Result<&str>..
1740: 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 where I: Into<i6
1750: 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 6d 61 74 4> {...match mat
1760: 63 68 20 75 70 64 61 74 65 20 7b 0a 09 09 09 09 ch update {.....
1770: 53 6f 6d 65 28 69 64 29 20 3d 3e 20 7b 0a 09 09 Some(id) => {...
1780: 09 09 09 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 ...sqlx::query("
1790: 75 70 64 61 74 65 20 72 73 73 74 67 5f 73 6f 75 update rsstg_sou
17a0: 72 63 65 20 73 65 74 20 63 68 61 6e 6e 65 6c 5f rce set channel_
17b0: 69 64 20 3d 20 24 32 2c 20 75 72 6c 20 3d 20 24 id = $2, url = $
17c0: 33 2c 20 69 76 5f 68 61 73 68 20 3d 20 24 34 2c 3, iv_hash = $4,
17d0: 20 6f 77 6e 65 72 20 3d 20 24 35 2c 20 63 68 61 owner = $5, cha
17e0: 6e 6e 65 6c 20 3d 20 24 36 2c 20 75 72 6c 5f 72 nnel = $6, url_r
17f0: 65 20 3d 20 24 37 20 77 68 65 72 65 20 73 6f 75 e = $7 where sou
1800: 72 63 65 5f 69 64 20 3d 20 24 31 22 29 0a 09 09 rce_id = $1")...
1810: 09 09 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 .....bind(id)...
1820: 09 09 7d 2c 0a 09 09 09 09 4e 6f 6e 65 20 3d 3e ..},.....None =>
1830: 20 7b 0a 09 09 09 09 09 73 71 6c 78 3a 3a 71 75 {......sqlx::qu
1840: 65 72 79 28 22 69 6e 73 65 72 74 20 69 6e 74 6f ery("insert into
1850: 20 72 73 73 74 67 5f 73 6f 75 72 63 65 20 28 63 rsstg_source (c
1860: 68 61 6e 6e 65 6c 5f 69 64 2c 20 75 72 6c 2c 20 hannel_id, url,
1870: 69 76 5f 68 61 73 68 2c 20 6f 77 6e 65 72 2c 20 iv_hash, owner,
1880: 63 68 61 6e 6e 65 6c 2c 20 75 72 6c 5f 72 65 29 channel, url_re)
1890: 20 76 61 6c 75 65 73 20 28 24 31 2c 20 24 32 2c values ($1, $2,
18a0: 20 24 33 2c 20 24 34 2c 20 24 35 2c 20 24 36 29 $3, $4, $5, $6)
18b0: 22 29 0a 09 09 09 09 7d 2c 0a 09 09 09 7d 0a 09 ").....},....}..
18c0: 09 09 09 2e 62 69 6e 64 28 63 68 61 6e 6e 65 6c ....bind(channel
18d0: 5f 69 64 29 0a 09 09 09 09 2e 62 69 6e 64 28 75 _id)......bind(u
18e0: 72 6c 29 0a 09 09 09 09 2e 62 69 6e 64 28 69 76 rl)......bind(iv
18f0: 5f 68 61 73 68 29 0a 09 09 09 09 2e 62 69 6e 64 _hash)......bind
1900: 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 (owner.into())..
1910: 09 09 09 2e 62 69 6e 64 28 63 68 61 6e 6e 65 6c ....bind(channel
1920: 29 0a 09 09 09 09 2e 62 69 6e 64 28 75 72 6c 5f )......bind(url_
1930: 72 65 29 0a 09 09 09 09 2e 65 78 65 63 75 74 65 re)......execute
1940: 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 (&mut *self.0).a
1950: 77 61 69 74 0a 09 09 09 7b 0a 09 09 09 4f 6b 28 wait....{....Ok(
1960: 5f 29 20 3d 3e 20 4f 6b 28 6d 61 74 63 68 20 75 _) => Ok(match u
1970: 70 64 61 74 65 20 7b 0a 09 09 09 09 53 6f 6d 65 pdate {.....Some
1980: 28 5f 29 20 3d 3e 20 22 43 68 61 6e 6e 65 6c 20 (_) => "Channel
1990: 75 70 64 61 74 65 64 2e 22 2c 0a 09 09 09 09 4e updated.",.....N
19a0: 6f 6e 65 20 3d 3e 20 22 43 68 61 6e 6e 65 6c 20 one => "Channel
19b0: 61 64 64 65 64 2e 22 2c 0a 09 09 09 7d 29 2c 0a added.",....}),.
19c0: 09 09 09 45 72 72 28 73 71 6c 78 3a 3a 45 72 72 ...Err(sqlx::Err
19d0: 6f 72 3a 3a 44 61 74 61 62 61 73 65 28 65 72 72 or::Database(err
19e0: 29 29 20 3d 3e 20 7b 0a 09 09 09 09 6d 61 74 63 )) => {.....matc
19f0: 68 20 65 72 72 2e 64 6f 77 6e 63 61 73 74 3a 3a h err.downcast::
1a00: 3c 73 71 6c 78 3a 3a 70 6f 73 74 67 72 65 73 3a <sqlx::postgres:
1a10: 3a 50 67 44 61 74 61 62 61 73 65 45 72 72 6f 72 :PgDatabaseError
1a20: 3e 28 29 2e 72 6f 75 74 69 6e 65 28 29 20 7b 0a >().routine() {.
1a30: 09 09 09 09 09 53 6f 6d 65 28 22 5f 62 74 5f 63 .....Some("_bt_c
1a40: 68 65 63 6b 5f 75 6e 69 71 75 65 22 2c 20 29 20 heck_unique", )
1a50: 3d 3e 20 7b 0a 09 09 09 09 09 09 4f 6b 28 22 44 => {.......Ok("D
1a60: 75 70 6c 69 63 61 74 65 20 6b 65 79 2e 22 29 0a uplicate key.").
1a70: 09 09 09 09 09 7d 2c 0a 09 09 09 09 09 53 6f 6d .....},......Som
1a80: 65 28 5f 29 20 3d 3e 20 7b 0a 09 09 09 09 09 09 e(_) => {.......
1a90: 4f 6b 28 22 44 61 74 61 62 61 73 65 20 65 72 72 Ok("Database err
1aa0: 6f 72 2e 22 29 0a 09 09 09 09 09 7d 2c 0a 09 09 or.")......},...
1ab0: 09 09 09 4e 6f 6e 65 20 3d 3e 20 7b 0a 09 09 09 ...None => {....
1ac0: 09 09 09 4f 6b 28 22 4e 6f 20 64 61 74 61 62 61 ...Ok("No databa
1ad0: 73 65 20 65 72 72 6f 72 20 65 78 74 72 61 63 74 se error extract
1ae0: 65 64 2e 22 29 0a 09 09 09 09 09 7d 2c 0a 09 09 ed.")......},...
1af0: 09 09 7d 0a 09 09 09 7d 2c 0a 09 09 09 45 72 72 ..}....},....Err
1b00: 28 65 72 72 29 20 3d 3e 20 7b 0a 09 09 09 09 62 (err) => {.....b
1b10: 61 69 6c 21 28 22 53 6f 72 72 79 2c 20 75 6e 6b ail!("Sorry, unk
1b20: 6e 6f 77 6e 20 65 72 72 6f 72 3a 5c 6e 7b 65 72 nown error:\n{er
1b30: 72 3a 23 3f 7d 5c 6e 22 29 3b 0a 09 09 09 7d 2c r:#?}\n");....},
1b40: 0a 09 09 7d 0a 09 7d 0a 7d 0a ...}..}.}.