Hex Artifact Content
Logged in as anonymous

Artifact e784f243af776fdd64fc78c01ed6d32f3d90a4f30c1d018b0e79d982d463b827:


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 6e 79 68 6f 77 3a 3a 7b  ;..use anyhow::{
0030: 0a 09 52 65 73 75 6c 74 2c 0a 09 62 61 69 6c 2c  ..Result,..bail,
0040: 0a 7d 3b 0a 75 73 65 20 61 73 79 6e 63 5f 73 74  .};.use async_st
0050: 64 3a 3a 73 79 6e 63 3a 3a 7b 0a 09 41 72 63 2c  d::sync::{..Arc,
0060: 0a 09 4d 75 74 65 78 2c 0a 7d 3b 0a 75 73 65 20  ..Mutex,.};.use 
0070: 63 68 72 6f 6e 6f 3a 3a 7b 0a 09 44 61 74 65 54  chrono::{..DateT
0080: 69 6d 65 2c 0a 09 46 69 78 65 64 4f 66 66 73 65  ime,..FixedOffse
0090: 74 2c 0a 09 4c 6f 63 61 6c 2c 0a 7d 3b 0a 75 73  t,..Local,.};.us
00a0: 65 20 73 71 6c 78 3a 3a 7b 0a 09 50 6f 73 74 67  e sqlx::{..Postg
00b0: 72 65 73 2c 0a 09 52 6f 77 2c 0a 09 70 6f 73 74  res,..Row,..post
00c0: 67 72 65 73 3a 3a 50 67 50 6f 6f 6c 4f 70 74 69  gres::PgPoolOpti
00d0: 6f 6e 73 2c 0a 09 70 6f 6f 6c 3a 3a 50 6f 6f 6c  ons,..pool::Pool
00e0: 43 6f 6e 6e 65 63 74 69 6f 6e 2c 0a 7d 3b 0a 0a  Connection,.};..
00f0: 23 5b 64 65 72 69 76 65 28 73 71 6c 78 3a 3a 46  #[derive(sqlx::F
0100: 72 6f 6d 52 6f 77 2c 20 44 65 62 75 67 29 5d 0a  romRow, Debug)].
0110: 70 75 62 20 73 74 72 75 63 74 20 4c 69 73 74 20  pub struct List 
0120: 7b 0a 09 70 75 62 20 73 6f 75 72 63 65 5f 69 64  {..pub source_id
0130: 3a 20 69 33 32 2c 0a 09 70 75 62 20 63 68 61 6e  : i32,..pub chan
0140: 6e 65 6c 3a 20 53 74 72 69 6e 67 2c 0a 09 70 75  nel: String,..pu
0150: 62 20 65 6e 61 62 6c 65 64 3a 20 62 6f 6f 6c 2c  b enabled: bool,
0160: 0a 09 70 75 62 20 75 72 6c 3a 20 53 74 72 69 6e  ..pub url: Strin
0170: 67 2c 0a 09 70 75 62 20 69 76 5f 68 61 73 68 3a  g,..pub iv_hash:
0180: 20 4f 70 74 69 6f 6e 3c 53 74 72 69 6e 67 3e 2c   Option<String>,
0190: 0a 09 70 75 62 20 75 72 6c 5f 72 65 3a 20 4f 70  ..pub url_re: Op
01a0: 74 69 6f 6e 3c 53 74 72 69 6e 67 3e 2c 0a 7d 0a  tion<String>,.}.
01b0: 0a 69 6d 70 6c 20 66 6d 74 3a 3a 44 69 73 70 6c  .impl fmt::Displ
01c0: 61 79 20 66 6f 72 20 4c 69 73 74 20 7b 0a 09 66  ay for List {..f
01d0: 6e 20 66 6d 74 28 26 73 65 6c 66 2c 20 66 3a 20  n fmt(&self, f: 
01e0: 26 6d 75 74 20 66 6d 74 3a 3a 46 6f 72 6d 61 74  &mut fmt::Format
01f0: 74 65 72 3c 27 5f 3e 29 20 2d 3e 20 52 65 73 75  ter<'_>) -> Resu
0200: 6c 74 3c 28 29 2c 20 66 6d 74 3a 3a 45 72 72 6f  lt<(), fmt::Erro
0210: 72 3e 20 7b 0a 09 09 77 72 69 74 65 21 28 66 2c  r> {...write!(f,
0220: 20 22 23 7b 7d 20 5c 5c 2a ef b8 8f e2 83 a3 20   "#{} \\*ļøāƒ£ 
0230: 60 7b 7d 60 20 7b 7d 5c 6e f0 9f 94 97 20 60 7b  `{}` {}\nšŸ”— `{
0240: 7d 60 22 2c 20 73 65 6c 66 2e 73 6f 75 72 63 65  }`", self.source
0250: 5f 69 64 2c 20 73 65 6c 66 2e 63 68 61 6e 6e 65  _id, self.channe
0260: 6c 2c 0a 09 09 09 6d 61 74 63 68 20 73 65 6c 66  l,....match self
0270: 2e 65 6e 61 62 6c 65 64 20 7b 0a 09 09 09 09 74  .enabled {.....t
0280: 72 75 65 20 20 3d 3e 20 22 f0 9f 94 84 20 65 6e  rue  => "šŸ”„ en
0290: 61 62 6c 65 64 22 2c 0a 09 09 09 09 66 61 6c 73  abled",.....fals
02a0: 65 20 3d 3e 20 22 e2 9b 94 20 64 69 73 61 62 6c  e => "ā›” disabl
02b0: 65 64 22 2c 0a 09 09 09 7d 2c 20 73 65 6c 66 2e  ed",....}, self.
02c0: 75 72 6c 29 3f 3b 0a 09 09 69 66 20 6c 65 74 20  url)?;...if let 
02d0: 53 6f 6d 65 28 69 76 5f 68 61 73 68 29 20 3d 20  Some(iv_hash) = 
02e0: 26 73 65 6c 66 2e 69 76 5f 68 61 73 68 20 7b 0a  &self.iv_hash {.
02f0: 09 09 09 77 72 69 74 65 21 28 66 2c 20 22 5c 6e  ...write!(f, "\n
0300: 49 56 3a 20 60 7b 69 76 5f 68 61 73 68 7d 60 22  IV: `{iv_hash}`"
0310: 29 3f 3b 0a 09 09 7d 0a 09 09 69 66 20 6c 65 74  )?;...}...if let
0320: 20 53 6f 6d 65 28 75 72 6c 5f 72 65 29 20 3d 20   Some(url_re) = 
0330: 26 73 65 6c 66 2e 75 72 6c 5f 72 65 20 7b 0a 09  &self.url_re {..
0340: 09 09 77 72 69 74 65 21 28 66 2c 20 22 5c 6e 52  ..write!(f, "\nR
0350: 45 3a 20 60 7b 75 72 6c 5f 72 65 7d 60 22 29 3f  E: `{url_re}`")?
0360: 3b 0a 09 09 7d 0a 09 09 4f 6b 28 28 29 29 0a 09  ;...}...Ok(())..
0370: 7d 0a 7d 0a 0a 23 5b 64 65 72 69 76 65 28 73 71  }.}..#[derive(sq
0380: 6c 78 3a 3a 46 72 6f 6d 52 6f 77 2c 20 44 65 62  lx::FromRow, Deb
0390: 75 67 29 5d 0a 70 75 62 20 73 74 72 75 63 74 20  ug)].pub struct 
03a0: 53 6f 75 72 63 65 20 7b 0a 09 70 75 62 20 63 68  Source {..pub ch
03b0: 61 6e 6e 65 6c 5f 69 64 3a 20 69 36 34 2c 0a 09  annel_id: i64,..
03c0: 70 75 62 20 75 72 6c 3a 20 53 74 72 69 6e 67 2c  pub url: String,
03d0: 0a 09 70 75 62 20 69 76 5f 68 61 73 68 3a 20 4f  ..pub iv_hash: O
03e0: 70 74 69 6f 6e 3c 53 74 72 69 6e 67 3e 2c 0a 09  ption<String>,..
03f0: 70 75 62 20 6f 77 6e 65 72 3a 20 69 36 34 2c 0a  pub owner: i64,.
0400: 09 70 75 62 20 75 72 6c 5f 72 65 3a 20 4f 70 74  .pub url_re: Opt
0410: 69 6f 6e 3c 53 74 72 69 6e 67 3e 2c 0a 7d 0a 0a  ion<String>,.}..
0420: 23 5b 64 65 72 69 76 65 28 73 71 6c 78 3a 3a 46  #[derive(sqlx::F
0430: 72 6f 6d 52 6f 77 29 5d 0a 70 75 62 20 73 74 72  romRow)].pub str
0440: 75 63 74 20 51 75 65 75 65 20 7b 0a 09 70 75 62  uct Queue {..pub
0450: 20 73 6f 75 72 63 65 5f 69 64 3a 20 4f 70 74 69   source_id: Opti
0460: 6f 6e 3c 69 33 32 3e 2c 0a 09 70 75 62 20 6e 65  on<i32>,..pub ne
0470: 78 74 5f 66 65 74 63 68 3a 20 4f 70 74 69 6f 6e  xt_fetch: Option
0480: 3c 44 61 74 65 54 69 6d 65 3c 4c 6f 63 61 6c 3e  <DateTime<Local>
0490: 3e 2c 0a 09 70 75 62 20 6f 77 6e 65 72 3a 20 4f  >,..pub owner: O
04a0: 70 74 69 6f 6e 3c 69 36 34 3e 2c 0a 7d 0a 0a 23  ption<i64>,.}..#
04b0: 5b 64 65 72 69 76 65 28 43 6c 6f 6e 65 29 5d 0a  [derive(Clone)].
04c0: 70 75 62 20 73 74 72 75 63 74 20 44 62 20 28 0a  pub struct Db (.
04d0: 09 41 72 63 3c 4d 75 74 65 78 3c 73 71 6c 78 3a  .Arc<Mutex<sqlx:
04e0: 3a 50 6f 6f 6c 3c 73 71 6c 78 3a 3a 50 6f 73 74  :Pool<sqlx::Post
04f0: 67 72 65 73 3e 3e 3e 2c 0a 29 3b 0a 0a 69 6d 70  gres>>>,.);..imp
0500: 6c 20 44 62 20 7b 0a 09 70 75 62 20 66 6e 20 6e  l Db {..pub fn n
0510: 65 77 20 28 70 67 75 72 69 3a 20 26 73 74 72 29  ew (pguri: &str)
0520: 20 2d 3e 20 52 65 73 75 6c 74 3c 44 62 3e 20 7b   -> Result<Db> {
0530: 0a 09 09 4f 6b 28 44 62 20 28 0a 09 09 09 41 72  ...Ok(Db (....Ar
0540: 63 3a 3a 6e 65 77 28 4d 75 74 65 78 3a 3a 6e 65  c::new(Mutex::ne
0550: 77 28 50 67 50 6f 6f 6c 4f 70 74 69 6f 6e 73 3a  w(PgPoolOptions:
0560: 3a 6e 65 77 28 29 0a 09 09 09 09 2e 6d 61 78 5f  :new()......max_
0570: 63 6f 6e 6e 65 63 74 69 6f 6e 73 28 35 29 0a 09  connections(5)..
0580: 09 09 09 2e 61 63 71 75 69 72 65 5f 74 69 6d 65  ....acquire_time
0590: 6f 75 74 28 73 74 64 3a 3a 74 69 6d 65 3a 3a 44  out(std::time::D
05a0: 75 72 61 74 69 6f 6e 3a 3a 6e 65 77 28 33 30 30  uration::new(300
05b0: 2c 20 30 29 29 0a 09 09 09 09 2e 69 64 6c 65 5f  , 0))......idle_
05c0: 74 69 6d 65 6f 75 74 28 73 74 64 3a 3a 74 69 6d  timeout(std::tim
05d0: 65 3a 3a 44 75 72 61 74 69 6f 6e 3a 3a 6e 65 77  e::Duration::new
05e0: 28 36 30 2c 20 30 29 29 0a 09 09 09 09 2e 63 6f  (60, 0))......co
05f0: 6e 6e 65 63 74 5f 6c 61 7a 79 28 70 67 75 72 69  nnect_lazy(pguri
0600: 29 3f 29 29 2c 0a 09 09 29 29 0a 09 7d 0a 0a 09  )?)),...))..}...
0610: 70 75 62 20 61 73 79 6e 63 20 66 6e 20 62 65 67  pub async fn beg
0620: 69 6e 28 26 73 65 6c 66 29 20 2d 3e 20 52 65 73  in(&self) -> Res
0630: 75 6c 74 3c 43 6f 6e 6e 3e 20 7b 0a 09 09 6c 65  ult<Conn> {...le
0640: 74 20 70 6f 6f 6c 20 3d 20 73 65 6c 66 2e 30 2e  t pool = self.0.
0650: 6c 6f 63 6b 5f 61 72 63 28 29 2e 61 77 61 69 74  lock_arc().await
0660: 3b 0a 09 09 6c 65 74 20 63 6f 6e 6e 20 3d 20 43  ;...let conn = C
0670: 6f 6e 6e 20 28 20 70 6f 6f 6c 2e 61 63 71 75 69  onn ( pool.acqui
0680: 72 65 28 29 2e 61 77 61 69 74 3f 20 29 3b 0a 09  re().await? );..
0690: 09 4f 6b 28 63 6f 6e 6e 29 0a 09 7d 0a 7d 0a 0a  .Ok(conn)..}.}..
06a0: 70 75 62 20 73 74 72 75 63 74 20 43 6f 6e 6e 20  pub struct Conn 
06b0: 28 0a 09 50 6f 6f 6c 43 6f 6e 6e 65 63 74 69 6f  (..PoolConnectio
06c0: 6e 3c 50 6f 73 74 67 72 65 73 3e 2c 0a 29 3b 0a  n<Postgres>,.);.
06d0: 0a 69 6d 70 6c 20 43 6f 6e 6e 20 7b 0a 09 70 75  .impl Conn {..pu
06e0: 62 20 61 73 79 6e 63 20 66 6e 20 61 64 64 5f 70  b async fn add_p
06f0: 6f 73 74 20 28 26 6d 75 74 20 73 65 6c 66 2c 20  ost (&mut self, 
0700: 73 6f 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 20  source_id: i32, 
0710: 64 61 74 65 3a 20 26 44 61 74 65 54 69 6d 65 3c  date: &DateTime<
0720: 46 69 78 65 64 4f 66 66 73 65 74 3e 2c 20 70 6f  FixedOffset>, po
0730: 73 74 5f 75 72 6c 3a 20 26 73 74 72 29 20 2d 3e  st_url: &str) ->
0740: 20 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09 09   Result<()> {...
0750: 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 69 6e 73  sqlx::query("ins
0760: 65 72 74 20 69 6e 74 6f 20 72 73 73 74 67 5f 70  ert into rsstg_p
0770: 6f 73 74 20 28 73 6f 75 72 63 65 5f 69 64 2c 20  ost (source_id, 
0780: 70 6f 73 74 65 64 2c 20 75 72 6c 29 20 76 61 6c  posted, url) val
0790: 75 65 73 20 28 24 31 2c 20 24 32 2c 20 24 33 29  ues ($1, $2, $3)
07a0: 3b 22 29 0a 09 09 09 2e 62 69 6e 64 28 73 6f 75  ;").....bind(sou
07b0: 72 63 65 5f 69 64 29 0a 09 09 09 2e 62 69 6e 64  rce_id).....bind
07c0: 28 64 61 74 65 29 0a 09 09 09 2e 62 69 6e 64 28  (date).....bind(
07d0: 70 6f 73 74 5f 75 72 6c 29 0a 09 09 09 2e 65 78  post_url).....ex
07e0: 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 6c 66  ecute(&mut *self
07f0: 2e 30 29 2e 61 77 61 69 74 3f 3b 0a 09 09 4f 6b  .0).await?;...Ok
0800: 28 28 29 29 0a 09 7d 0a 0a 09 70 75 62 20 61 73  (())..}...pub as
0810: 79 6e 63 20 66 6e 20 63 6c 65 61 6e 20 3c 49 3e  ync fn clean <I>
0820: 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 73 6f 75   (&mut self, sou
0830: 72 63 65 5f 69 64 3a 20 69 33 32 2c 20 6f 77 6e  rce_id: i32, own
0840: 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c 74  er: I) -> Result
0850: 3c 43 6f 77 3c 27 5f 2c 20 73 74 72 3e 3e 0a 09  <Cow<'_, str>>..
0860: 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36  where I: Into<i6
0870: 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 73 71 6c  4> {...match sql
0880: 78 3a 3a 71 75 65 72 79 28 22 64 65 6c 65 74 65  x::query("delete
0890: 20 66 72 6f 6d 20 72 73 73 74 67 5f 70 6f 73 74   from rsstg_post
08a0: 20 70 20 75 73 69 6e 67 20 72 73 73 74 67 5f 73   p using rsstg_s
08b0: 6f 75 72 63 65 20 73 20 77 68 65 72 65 20 70 2e  ource s where p.
08c0: 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 31 20 61  source_id = $1 a
08d0: 6e 64 20 6f 77 6e 65 72 20 3d 20 24 32 20 61 6e  nd owner = $2 an
08e0: 64 20 70 2e 73 6f 75 72 63 65 5f 69 64 20 3d 20  d p.source_id = 
08f0: 73 2e 73 6f 75 72 63 65 5f 69 64 3b 22 29 0a 09  s.source_id;")..
0900: 09 09 2e 62 69 6e 64 28 73 6f 75 72 63 65 5f 69  ...bind(source_i
0910: 64 29 0a 09 09 09 2e 62 69 6e 64 28 6f 77 6e 65  d).....bind(owne
0920: 72 2e 69 6e 74 6f 28 29 29 0a 09 09 09 2e 65 78  r.into()).....ex
0930: 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 6c 66  ecute(&mut *self
0940: 2e 30 29 2e 61 77 61 69 74 3f 2e 72 6f 77 73 5f  .0).await?.rows_
0950: 61 66 66 65 63 74 65 64 28 29 20 7b 0a 09 09 09  affected() {....
0960: 30 20 3d 3e 20 7b 20 4f 6b 28 22 4e 6f 20 64 61  0 => { Ok("No da
0970: 74 61 20 66 6f 75 6e 64 20 66 6f 75 6e 64 2e 22  ta found found."
0980: 2e 69 6e 74 6f 28 29 29 20 7d 2c 0a 09 09 09 78  .into()) },....x
0990: 20 3d 3e 20 7b 20 4f 6b 28 66 6f 72 6d 61 74 21   => { Ok(format!
09a0: 28 22 7b 78 7d 20 70 6f 73 74 73 20 70 75 72 67  ("{x} posts purg
09b0: 65 64 2e 22 29 2e 69 6e 74 6f 28 29 29 20 7d 2c  ed.").into()) },
09c0: 0a 09 09 7d 0a 09 7d 0a 0a 09 70 75 62 20 61 73  ...}..}...pub as
09d0: 79 6e 63 20 66 6e 20 64 65 6c 65 74 65 20 3c 49  ync fn delete <I
09e0: 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 73 6f  > (&mut self, so
09f0: 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 20 6f 77  urce_id: i32, ow
0a00: 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c  ner: I) -> Resul
0a10: 74 3c 43 6f 77 3c 27 5f 2c 20 73 74 72 3e 3e 0a  t<Cow<'_, str>>.
0a20: 09 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69  .where I: Into<i
0a30: 36 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 73 71  64> {...match sq
0a40: 6c 78 3a 3a 71 75 65 72 79 28 22 64 65 6c 65 74  lx::query("delet
0a50: 65 20 66 72 6f 6d 20 72 73 73 74 67 5f 73 6f 75  e from rsstg_sou
0a60: 72 63 65 20 77 68 65 72 65 20 73 6f 75 72 63 65  rce where source
0a70: 5f 69 64 20 3d 20 24 31 20 61 6e 64 20 6f 77 6e  _id = $1 and own
0a80: 65 72 20 3d 20 24 32 3b 22 29 0a 09 09 09 2e 62  er = $2;").....b
0a90: 69 6e 64 28 73 6f 75 72 63 65 5f 69 64 29 0a 09  ind(source_id)..
0aa0: 09 09 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e  ...bind(owner.in
0ab0: 74 6f 28 29 29 0a 09 09 09 2e 65 78 65 63 75 74  to()).....execut
0ac0: 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e  e(&mut *self.0).
0ad0: 61 77 61 69 74 3f 2e 72 6f 77 73 5f 61 66 66 65  await?.rows_affe
0ae0: 63 74 65 64 28 29 20 7b 0a 09 09 09 30 20 3d 3e  cted() {....0 =>
0af0: 20 7b 20 4f 6b 28 22 4e 6f 20 64 61 74 61 20 66   { Ok("No data f
0b00: 6f 75 6e 64 20 66 6f 75 6e 64 2e 22 2e 69 6e 74  ound found.".int
0b10: 6f 28 29 29 20 7d 2c 0a 09 09 09 78 20 3d 3e 20  o()) },....x => 
0b20: 7b 20 4f 6b 28 66 6f 72 6d 61 74 21 28 22 7b 7d  { Ok(format!("{}
0b30: 20 73 6f 75 72 63 65 73 20 72 65 6d 6f 76 65 64   sources removed
0b40: 2e 22 2c 20 78 29 2e 69 6e 74 6f 28 29 29 20 7d  .", x).into()) }
0b50: 2c 0a 09 09 7d 0a 09 7d 0a 0a 09 70 75 62 20 61  ,...}..}...pub a
0b60: 73 79 6e 63 20 66 6e 20 64 69 73 61 62 6c 65 20  sync fn disable 
0b70: 3c 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20  <I> (&mut self, 
0b80: 73 6f 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 20  source_id: i32, 
0b90: 6f 77 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73  owner: I) -> Res
0ba0: 75 6c 74 3c 26 73 74 72 3e 0a 09 77 68 65 72 65  ult<&str>..where
0bb0: 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a   I: Into<i64> {.
0bc0: 09 09 6d 61 74 63 68 20 73 71 6c 78 3a 3a 71 75  ..match sqlx::qu
0bd0: 65 72 79 28 22 75 70 64 61 74 65 20 72 73 73 74  ery("update rsst
0be0: 67 5f 73 6f 75 72 63 65 20 73 65 74 20 65 6e 61  g_source set ena
0bf0: 62 6c 65 64 20 3d 20 66 61 6c 73 65 20 77 68 65  bled = false whe
0c00: 72 65 20 73 6f 75 72 63 65 5f 69 64 20 3d 20 24  re source_id = $
0c10: 31 20 61 6e 64 20 6f 77 6e 65 72 20 3d 20 24 32  1 and owner = $2
0c20: 22 29 0a 09 09 09 2e 62 69 6e 64 28 73 6f 75 72  ").....bind(sour
0c30: 63 65 5f 69 64 29 0a 09 09 09 2e 62 69 6e 64 28  ce_id).....bind(
0c40: 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 09  owner.into())...
0c50: 09 2e 65 78 65 63 75 74 65 28 26 6d 75 74 20 2a  ..execute(&mut *
0c60: 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 3f 2e 72  self.0).await?.r
0c70: 6f 77 73 5f 61 66 66 65 63 74 65 64 28 29 20 7b  ows_affected() {
0c80: 0a 09 09 09 31 20 3d 3e 20 7b 20 4f 6b 28 22 53  ....1 => { Ok("S
0c90: 6f 75 72 63 65 20 64 69 73 61 62 6c 65 64 2e 22  ource disabled."
0ca0: 29 20 7d 2c 0a 09 09 09 30 20 3d 3e 20 7b 20 4f  ) },....0 => { O
0cb0: 6b 28 22 53 6f 75 72 63 65 20 6e 6f 74 20 66 6f  k("Source not fo
0cc0: 75 6e 64 2e 22 29 20 7d 2c 0a 09 09 09 5f 20 3d  und.") },...._ =
0cd0: 3e 20 7b 20 62 61 69 6c 21 28 22 44 61 74 61 62  > { bail!("Datab
0ce0: 61 73 65 20 65 72 72 6f 72 2e 22 29 20 7d 2c 0a  ase error.") },.
0cf0: 09 09 7d 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79  ..}..}...pub asy
0d00: 6e 63 20 66 6e 20 65 6e 61 62 6c 65 20 3c 49 3e  nc fn enable <I>
0d10: 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 73 6f 75   (&mut self, sou
0d20: 72 63 65 5f 69 64 3a 20 69 33 32 2c 20 6f 77 6e  rce_id: i32, own
0d30: 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c 74  er: I) -> Result
0d40: 3c 26 73 74 72 3e 0a 09 77 68 65 72 65 20 49 3a  <&str>..where I:
0d50: 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6d   Into<i64> {...m
0d60: 61 74 63 68 20 73 71 6c 78 3a 3a 71 75 65 72 79  atch sqlx::query
0d70: 28 22 75 70 64 61 74 65 20 72 73 73 74 67 5f 73  ("update rsstg_s
0d80: 6f 75 72 63 65 20 73 65 74 20 65 6e 61 62 6c 65  ource set enable
0d90: 64 20 3d 20 74 72 75 65 20 77 68 65 72 65 20 73  d = true where s
0da0: 6f 75 72 63 65 5f 69 64 20 3d 20 24 31 20 61 6e  ource_id = $1 an
0db0: 64 20 6f 77 6e 65 72 20 3d 20 24 32 22 29 0a 09  d owner = $2")..
0dc0: 09 09 2e 62 69 6e 64 28 73 6f 75 72 63 65 5f 69  ...bind(source_i
0dd0: 64 29 0a 09 09 09 2e 62 69 6e 64 28 6f 77 6e 65  d).....bind(owne
0de0: 72 2e 69 6e 74 6f 28 29 29 0a 09 09 09 2e 65 78  r.into()).....ex
0df0: 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 6c 66  ecute(&mut *self
0e00: 2e 30 29 2e 61 77 61 69 74 3f 2e 72 6f 77 73 5f  .0).await?.rows_
0e10: 61 66 66 65 63 74 65 64 28 29 20 7b 0a 09 09 09  affected() {....
0e20: 31 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 72 63  1 => { Ok("Sourc
0e30: 65 20 65 6e 61 62 6c 65 64 2e 22 29 20 7d 2c 0a  e enabled.") },.
0e40: 09 09 09 30 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f  ...0 => { Ok("So
0e50: 75 72 63 65 20 6e 6f 74 20 66 6f 75 6e 64 2e 22  urce not found."
0e60: 29 20 7d 2c 0a 09 09 09 5f 20 3d 3e 20 7b 20 62  ) },...._ => { b
0e70: 61 69 6c 21 28 22 44 61 74 61 62 61 73 65 20 65  ail!("Database e
0e80: 72 72 6f 72 2e 22 29 20 7d 2c 0a 09 09 7d 0a 09  rror.") },...}..
0e90: 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e  }...pub async fn
0ea0: 20 65 78 69 73 74 73 20 3c 49 3e 20 28 26 6d 75   exists <I> (&mu
0eb0: 74 20 73 65 6c 66 2c 20 70 6f 73 74 5f 75 72 6c  t self, post_url
0ec0: 3a 20 26 73 74 72 2c 20 69 64 3a 20 49 29 20 2d  : &str, id: I) -
0ed0: 3e 20 52 65 73 75 6c 74 3c 4f 70 74 69 6f 6e 3c  > Result<Option<
0ee0: 62 6f 6f 6c 3e 3e 0a 09 77 68 65 72 65 20 49 3a  bool>>..where I:
0ef0: 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c   Into<i64> {...l
0f00: 65 74 20 72 6f 77 20 3d 20 73 71 6c 78 3a 3a 71  et row = sqlx::q
0f10: 75 65 72 79 28 22 73 65 6c 65 63 74 20 65 78 69  uery("select exi
0f20: 73 74 73 28 73 65 6c 65 63 74 20 74 72 75 65 20  sts(select true 
0f30: 66 72 6f 6d 20 72 73 73 74 67 5f 70 6f 73 74 20  from rsstg_post 
0f40: 77 68 65 72 65 20 75 72 6c 20 3d 20 24 31 20 61  where url = $1 a
0f50: 6e 64 20 73 6f 75 72 63 65 5f 69 64 20 3d 20 24  nd source_id = $
0f60: 32 29 20 61 73 20 65 78 69 73 74 73 3b 22 29 0a  2) as exists;").
0f70: 09 09 09 2e 62 69 6e 64 28 70 6f 73 74 5f 75 72  ....bind(post_ur
0f80: 6c 29 0a 09 09 09 2e 62 69 6e 64 28 69 64 2e 69  l).....bind(id.i
0f90: 6e 74 6f 28 29 29 0a 09 09 09 2e 66 65 74 63 68  nto()).....fetch
0fa0: 5f 6f 6e 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e  _one(&mut *self.
0fb0: 30 29 2e 61 77 61 69 74 3f 3b 0a 09 09 6c 65 74  0).await?;...let
0fc0: 20 65 78 69 73 74 73 3a 20 4f 70 74 69 6f 6e 3c   exists: Option<
0fd0: 62 6f 6f 6c 3e 20 3d 20 72 6f 77 2e 74 72 79 5f  bool> = row.try_
0fe0: 67 65 74 28 22 65 78 69 73 74 73 22 29 3f 3b 0a  get("exists")?;.
0ff0: 09 09 4f 6b 28 65 78 69 73 74 73 29 0a 09 7d 0a  ..Ok(exists)..}.
1000: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 67  ..pub async fn g
1010: 65 74 5f 71 75 65 75 65 20 28 26 6d 75 74 20 73  et_queue (&mut s
1020: 65 6c 66 29 20 2d 3e 20 52 65 73 75 6c 74 3c 56  elf) -> Result<V
1030: 65 63 3c 51 75 65 75 65 3e 3e 20 7b 0a 09 09 6c  ec<Queue>> {...l
1040: 65 74 20 62 6c 6f 63 6b 3a 20 56 65 63 3c 51 75  et block: Vec<Qu
1050: 65 75 65 3e 20 3d 20 73 71 6c 78 3a 3a 71 75 65  eue> = sqlx::que
1060: 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 73 6f  ry_as("select so
1070: 75 72 63 65 5f 69 64 2c 20 6e 65 78 74 5f 66 65  urce_id, next_fe
1080: 74 63 68 2c 20 6f 77 6e 65 72 20 66 72 6f 6d 20  tch, owner from 
1090: 72 73 73 74 67 5f 6f 72 64 65 72 20 6e 61 74 75  rsstg_order natu
10a0: 72 61 6c 20 6c 65 66 74 20 6a 6f 69 6e 20 72 73  ral left join rs
10b0: 73 74 67 5f 73 6f 75 72 63 65 20 77 68 65 72 65  stg_source where
10c0: 20 6e 65 78 74 5f 66 65 74 63 68 20 3c 20 6e 6f   next_fetch < no
10d0: 77 28 29 20 2b 20 69 6e 74 65 72 76 61 6c 20 27  w() + interval '
10e0: 31 20 6d 69 6e 75 74 65 27 3b 22 29 0a 09 09 09  1 minute';")....
10f0: 2e 66 65 74 63 68 5f 61 6c 6c 28 26 6d 75 74 20  .fetch_all(&mut 
1100: 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 3f 3b  *self.0).await?;
1110: 0a 09 09 4f 6b 28 62 6c 6f 63 6b 29 0a 09 7d 0a  ...Ok(block)..}.
1120: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 67  ..pub async fn g
1130: 65 74 5f 6c 69 73 74 20 3c 49 3e 20 28 26 6d 75  et_list <I> (&mu
1140: 74 20 73 65 6c 66 2c 20 6f 77 6e 65 72 3a 20 49  t self, owner: I
1150: 29 20 2d 3e 20 52 65 73 75 6c 74 3c 56 65 63 3c  ) -> Result<Vec<
1160: 4c 69 73 74 3e 3e 0a 09 77 68 65 72 65 20 49 3a  List>>..where I:
1170: 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c   Into<i64> {...l
1180: 65 74 20 73 6f 75 72 63 65 3a 20 56 65 63 3c 4c  et source: Vec<L
1190: 69 73 74 3e 20 3d 20 73 71 6c 78 3a 3a 71 75 65  ist> = sqlx::que
11a0: 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 73 6f  ry_as("select so
11b0: 75 72 63 65 5f 69 64 2c 20 63 68 61 6e 6e 65 6c  urce_id, channel
11c0: 2c 20 65 6e 61 62 6c 65 64 2c 20 75 72 6c 2c 20  , enabled, url, 
11d0: 69 76 5f 68 61 73 68 2c 20 75 72 6c 5f 72 65 20  iv_hash, url_re 
11e0: 66 72 6f 6d 20 72 73 73 74 67 5f 73 6f 75 72 63  from rsstg_sourc
11f0: 65 20 77 68 65 72 65 20 6f 77 6e 65 72 20 3d 20  e where owner = 
1200: 24 31 20 6f 72 64 65 72 20 62 79 20 73 6f 75 72  $1 order by sour
1210: 63 65 5f 69 64 22 29 0a 09 09 09 2e 62 69 6e 64  ce_id").....bind
1220: 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09  (owner.into())..
1230: 09 09 2e 66 65 74 63 68 5f 61 6c 6c 28 26 6d 75  ...fetch_all(&mu
1240: 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 74  t *self.0).await
1250: 3f 3b 0a 09 09 4f 6b 28 73 6f 75 72 63 65 29 0a  ?;...Ok(source).
1260: 09 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66  .}...pub async f
1270: 6e 20 67 65 74 5f 6f 6e 65 20 3c 49 3e 20 28 26  n get_one <I> (&
1280: 6d 75 74 20 73 65 6c 66 2c 20 6f 77 6e 65 72 3a  mut self, owner:
1290: 20 49 2c 20 69 64 3a 20 69 33 32 29 20 2d 3e 20   I, id: i32) -> 
12a0: 52 65 73 75 6c 74 3c 4f 70 74 69 6f 6e 3c 4c 69  Result<Option<Li
12b0: 73 74 3e 3e 0a 09 77 68 65 72 65 20 49 3a 20 49  st>>..where I: I
12c0: 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c 65 74  nto<i64> {...let
12d0: 20 73 6f 75 72 63 65 3a 20 4f 70 74 69 6f 6e 3c   source: Option<
12e0: 4c 69 73 74 3e 20 3d 20 73 71 6c 78 3a 3a 71 75  List> = sqlx::qu
12f0: 65 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 73  ery_as("select s
1300: 6f 75 72 63 65 5f 69 64 2c 20 63 68 61 6e 6e 65  ource_id, channe
1310: 6c 2c 20 65 6e 61 62 6c 65 64 2c 20 75 72 6c 2c  l, enabled, url,
1320: 20 69 76 5f 68 61 73 68 2c 20 75 72 6c 5f 72 65   iv_hash, url_re
1330: 20 66 72 6f 6d 20 72 73 73 74 67 5f 73 6f 75 72   from rsstg_sour
1340: 63 65 20 77 68 65 72 65 20 6f 77 6e 65 72 20 3d  ce where owner =
1350: 20 24 31 20 61 6e 64 20 73 6f 75 72 63 65 5f 69   $1 and source_i
1360: 64 20 3d 20 24 32 22 29 0a 09 09 09 2e 62 69 6e  d = $2").....bin
1370: 64 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a  d(owner.into()).
1380: 09 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 09  ....bind(id)....
1390: 2e 66 65 74 63 68 5f 6f 70 74 69 6f 6e 61 6c 28  .fetch_optional(
13a0: 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77  &mut *self.0).aw
13b0: 61 69 74 3f 3b 0a 09 09 4f 6b 28 73 6f 75 72 63  ait?;...Ok(sourc
13c0: 65 29 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 6e  e)..}...pub asyn
13d0: 63 20 66 6e 20 67 65 74 5f 73 6f 75 72 63 65 20  c fn get_source 
13e0: 3c 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20  <I> (&mut self, 
13f0: 69 64 3a 20 69 33 32 2c 20 6f 77 6e 65 72 3a 20  id: i32, owner: 
1400: 49 29 20 2d 3e 20 52 65 73 75 6c 74 3c 53 6f 75  I) -> Result<Sou
1410: 72 63 65 3e 0a 09 77 68 65 72 65 20 49 3a 20 49  rce>..where I: I
1420: 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c 65 74  nto<i64> {...let
1430: 20 73 6f 75 72 63 65 3a 20 53 6f 75 72 63 65 20   source: Source 
1440: 3d 20 73 71 6c 78 3a 3a 71 75 65 72 79 5f 61 73  = sqlx::query_as
1450: 28 22 73 65 6c 65 63 74 20 63 68 61 6e 6e 65 6c  ("select channel
1460: 5f 69 64 2c 20 75 72 6c 2c 20 69 76 5f 68 61 73  _id, url, iv_has
1470: 68 2c 20 6f 77 6e 65 72 2c 20 75 72 6c 5f 72 65  h, owner, url_re
1480: 20 66 72 6f 6d 20 72 73 73 74 67 5f 73 6f 75 72   from rsstg_sour
1490: 63 65 20 77 68 65 72 65 20 73 6f 75 72 63 65 5f  ce where source_
14a0: 69 64 20 3d 20 24 31 20 61 6e 64 20 6f 77 6e 65  id = $1 and owne
14b0: 72 20 3d 20 24 32 22 29 0a 09 09 09 2e 62 69 6e  r = $2").....bin
14c0: 64 28 69 64 29 0a 09 09 09 2e 62 69 6e 64 28 6f  d(id).....bind(o
14d0: 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 09 09  wner.into())....
14e0: 2e 66 65 74 63 68 5f 6f 6e 65 28 26 6d 75 74 20  .fetch_one(&mut 
14f0: 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 3f 3b  *self.0).await?;
1500: 0a 09 09 4f 6b 28 73 6f 75 72 63 65 29 0a 09 7d  ...Ok(source)..}
1510: 0a 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20  ...pub async fn 
1520: 73 65 74 5f 73 63 72 61 70 65 20 3c 49 3e 20 28  set_scrape <I> (
1530: 26 6d 75 74 20 73 65 6c 66 2c 20 69 64 3a 20 49  &mut self, id: I
1540: 29 20 2d 3e 20 52 65 73 75 6c 74 3c 28 29 3e 0a  ) -> Result<()>.
1550: 09 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69  .where I: Into<i
1560: 36 34 3e 20 7b 0a 09 09 73 71 6c 78 3a 3a 71 75  64> {...sqlx::qu
1570: 65 72 79 28 22 75 70 64 61 74 65 20 72 73 73 74  ery("update rsst
1580: 67 5f 73 6f 75 72 63 65 20 73 65 74 20 6c 61 73  g_source set las
1590: 74 5f 73 63 72 61 70 65 20 3d 20 6e 6f 77 28 29  t_scrape = now()
15a0: 20 77 68 65 72 65 20 73 6f 75 72 63 65 5f 69 64   where source_id
15b0: 20 3d 20 24 31 3b 22 29 0a 09 09 09 2e 62 69 6e   = $1;").....bin
15c0: 64 28 69 64 2e 69 6e 74 6f 28 29 29 0a 09 09 09  d(id.into())....
15d0: 2e 65 78 65 63 75 74 65 28 26 6d 75 74 20 2a 73  .execute(&mut *s
15e0: 65 6c 66 2e 30 29 2e 61 77 61 69 74 3f 3b 0a 09  elf.0).await?;..
15f0: 09 4f 6b 28 28 29 29 0a 09 7d 0a 0a 09 70 75 62  .Ok(())..}...pub
1600: 20 61 73 79 6e 63 20 66 6e 20 75 70 64 61 74 65   async fn update
1610: 20 3c 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c   <I> (&mut self,
1620: 20 75 70 64 61 74 65 3a 20 4f 70 74 69 6f 6e 3c   update: Option<
1630: 69 33 32 3e 2c 20 63 68 61 6e 6e 65 6c 3a 20 26  i32>, channel: &
1640: 73 74 72 2c 20 63 68 61 6e 6e 65 6c 5f 69 64 3a  str, channel_id:
1650: 20 69 36 34 2c 20 75 72 6c 3a 20 26 73 74 72 2c   i64, url: &str,
1660: 20 69 76 5f 68 61 73 68 3a 20 4f 70 74 69 6f 6e   iv_hash: Option
1670: 3c 26 73 74 72 3e 2c 20 75 72 6c 5f 72 65 3a 20  <&str>, url_re: 
1680: 4f 70 74 69 6f 6e 3c 26 73 74 72 3e 2c 20 6f 77  Option<&str>, ow
1690: 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c  ner: I) -> Resul
16a0: 74 3c 26 73 74 72 3e 0a 09 77 68 65 72 65 20 49  t<&str>..where I
16b0: 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09  : Into<i64> {...
16c0: 6d 61 74 63 68 20 6d 61 74 63 68 20 75 70 64 61  match match upda
16d0: 74 65 20 7b 0a 09 09 09 09 53 6f 6d 65 28 69 64  te {.....Some(id
16e0: 29 20 3d 3e 20 7b 0a 09 09 09 09 09 73 71 6c 78  ) => {......sqlx
16f0: 3a 3a 71 75 65 72 79 28 22 75 70 64 61 74 65 20  ::query("update 
1700: 72 73 73 74 67 5f 73 6f 75 72 63 65 20 73 65 74  rsstg_source set
1710: 20 63 68 61 6e 6e 65 6c 5f 69 64 20 3d 20 24 32   channel_id = $2
1720: 2c 20 75 72 6c 20 3d 20 24 33 2c 20 69 76 5f 68  , url = $3, iv_h
1730: 61 73 68 20 3d 20 24 34 2c 20 6f 77 6e 65 72 20  ash = $4, owner 
1740: 3d 20 24 35 2c 20 63 68 61 6e 6e 65 6c 20 3d 20  = $5, channel = 
1750: 24 36 2c 20 75 72 6c 5f 72 65 20 3d 20 24 37 20  $6, url_re = $7 
1760: 77 68 65 72 65 20 73 6f 75 72 63 65 5f 69 64 20  where source_id 
1770: 3d 20 24 31 22 29 0a 09 09 09 09 09 09 2e 62 69  = $1")........bi
1780: 6e 64 28 69 64 29 0a 09 09 09 09 7d 2c 0a 09 09  nd(id).....},...
1790: 09 09 4e 6f 6e 65 20 3d 3e 20 7b 0a 09 09 09 09  ..None => {.....
17a0: 09 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 69 6e  .sqlx::query("in
17b0: 73 65 72 74 20 69 6e 74 6f 20 72 73 73 74 67 5f  sert into rsstg_
17c0: 73 6f 75 72 63 65 20 28 63 68 61 6e 6e 65 6c 5f  source (channel_
17d0: 69 64 2c 20 75 72 6c 2c 20 69 76 5f 68 61 73 68  id, url, iv_hash
17e0: 2c 20 6f 77 6e 65 72 2c 20 63 68 61 6e 6e 65 6c  , owner, channel
17f0: 2c 20 75 72 6c 5f 72 65 29 20 76 61 6c 75 65 73  , url_re) values
1800: 20 28 24 31 2c 20 24 32 2c 20 24 33 2c 20 24 34   ($1, $2, $3, $4
1810: 2c 20 24 35 2c 20 24 36 29 22 29 0a 09 09 09 09  , $5, $6)").....
1820: 7d 2c 0a 09 09 09 7d 0a 09 09 09 09 2e 62 69 6e  },....}......bin
1830: 64 28 63 68 61 6e 6e 65 6c 5f 69 64 29 0a 09 09  d(channel_id)...
1840: 09 09 2e 62 69 6e 64 28 75 72 6c 29 0a 09 09 09  ...bind(url)....
1850: 09 2e 62 69 6e 64 28 69 76 5f 68 61 73 68 29 0a  ..bind(iv_hash).
1860: 09 09 09 09 2e 62 69 6e 64 28 6f 77 6e 65 72 2e  .....bind(owner.
1870: 69 6e 74 6f 28 29 29 0a 09 09 09 09 2e 62 69 6e  into())......bin
1880: 64 28 63 68 61 6e 6e 65 6c 29 0a 09 09 09 09 2e  d(channel)......
1890: 62 69 6e 64 28 75 72 6c 5f 72 65 29 0a 09 09 09  bind(url_re)....
18a0: 09 2e 65 78 65 63 75 74 65 28 26 6d 75 74 20 2a  ..execute(&mut *
18b0: 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 0a 09 09  self.0).await...
18c0: 09 7b 0a 09 09 09 4f 6b 28 5f 29 20 3d 3e 20 4f  .{....Ok(_) => O
18d0: 6b 28 6d 61 74 63 68 20 75 70 64 61 74 65 20 7b  k(match update {
18e0: 0a 09 09 09 09 53 6f 6d 65 28 5f 29 20 3d 3e 20  .....Some(_) => 
18f0: 22 43 68 61 6e 6e 65 6c 20 75 70 64 61 74 65 64  "Channel updated
1900: 2e 22 2c 0a 09 09 09 09 4e 6f 6e 65 20 3d 3e 20  .",.....None => 
1910: 22 43 68 61 6e 6e 65 6c 20 61 64 64 65 64 2e 22  "Channel added."
1920: 2c 0a 09 09 09 7d 29 2c 0a 09 09 09 45 72 72 28  ,....}),....Err(
1930: 73 71 6c 78 3a 3a 45 72 72 6f 72 3a 3a 44 61 74  sqlx::Error::Dat
1940: 61 62 61 73 65 28 65 72 72 29 29 20 3d 3e 20 7b  abase(err)) => {
1950: 0a 09 09 09 09 6d 61 74 63 68 20 65 72 72 2e 64  .....match err.d
1960: 6f 77 6e 63 61 73 74 3a 3a 3c 73 71 6c 78 3a 3a  owncast::<sqlx::
1970: 70 6f 73 74 67 72 65 73 3a 3a 50 67 44 61 74 61  postgres::PgData
1980: 62 61 73 65 45 72 72 6f 72 3e 28 29 2e 72 6f 75  baseError>().rou
1990: 74 69 6e 65 28 29 20 7b 0a 09 09 09 09 09 53 6f  tine() {......So
19a0: 6d 65 28 22 5f 62 74 5f 63 68 65 63 6b 5f 75 6e  me("_bt_check_un
19b0: 69 71 75 65 22 2c 20 29 20 3d 3e 20 7b 0a 09 09  ique", ) => {...
19c0: 09 09 09 09 4f 6b 28 22 44 75 70 6c 69 63 61 74  ....Ok("Duplicat
19d0: 65 20 6b 65 79 2e 22 29 0a 09 09 09 09 09 7d 2c  e key.")......},
19e0: 0a 09 09 09 09 09 53 6f 6d 65 28 5f 29 20 3d 3e  ......Some(_) =>
19f0: 20 7b 0a 09 09 09 09 09 09 4f 6b 28 22 44 61 74   {.......Ok("Dat
1a00: 61 62 61 73 65 20 65 72 72 6f 72 2e 22 29 0a 09  abase error.")..
1a10: 09 09 09 09 7d 2c 0a 09 09 09 09 09 4e 6f 6e 65  ....},......None
1a20: 20 3d 3e 20 7b 0a 09 09 09 09 09 09 4f 6b 28 22   => {.......Ok("
1a30: 4e 6f 20 64 61 74 61 62 61 73 65 20 65 72 72 6f  No database erro
1a40: 72 20 65 78 74 72 61 63 74 65 64 2e 22 29 0a 09  r extracted.")..
1a50: 09 09 09 09 7d 2c 0a 09 09 09 09 7d 0a 09 09 09  ....},.....}....
1a60: 7d 2c 0a 09 09 09 45 72 72 28 65 72 72 29 20 3d  },....Err(err) =
1a70: 3e 20 7b 0a 09 09 09 09 62 61 69 6c 21 28 22 53  > {.....bail!("S
1a80: 6f 72 72 79 2c 20 75 6e 6b 6e 6f 77 6e 20 65 72  orry, unknown er
1a90: 72 6f 72 3a 5c 6e 7b 65 72 72 3a 23 3f 7d 5c 6e  ror:\n{err:#?}\n
1aa0: 22 29 3b 0a 09 09 09 7d 2c 0a 09 09 7d 0a 09 7d  ");....},...}..}
1ab0: 0a 7d 0a                                         .}.