Diff
Logged in as anonymous

Differences From Artifact [483b69f7a3]:

To Artifact [2fd09e58c3]:


1

2
3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18

1






2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-
+
-
-
-
-
-
-




+
+
+
+







use std::{
use std::borrow::Cow;
	borrow::Cow,
	sync::{
		Arc,
		Mutex,
	},
};

use anyhow::{
	Result,
	bail,
};
use async_std::sync::{
	Arc,
	Mutex,
};
use chrono::{
	DateTime,
	FixedOffset,
	Local,
};
use sqlx::{
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63

64
65
66
67

68
69
70
71
72

73
74
75
76
77
78
79
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60

61
62
63
64

65
66
67
68
69

70
71
72
73
74
75
76
77







-
+









-
+



-
+




-
+







	pub source_id: Option<i32>,
	pub next_fetch: Option<DateTime<Local>>,
	pub owner: Option<i64>,
}

#[derive(Clone)]
pub struct Db {
	pool: Arc<Mutex<Arc<sqlx::Pool<sqlx::Postgres>>>>,
	pool: Arc<Mutex<sqlx::Pool<sqlx::Postgres>>>,
}

pub struct Conn{
	conn: PoolConnection<Postgres>,
}

impl Db {
	pub fn new (pguri: &str) -> Result<Db> {
		Ok(Db{
			pool: Arc::new(Mutex::new(Arc::new(PgPoolOptions::new()
			pool: Arc::new(Mutex::new(PgPoolOptions::new()
				.max_connections(5)
				.acquire_timeout(std::time::Duration::new(300, 0))
				.idle_timeout(std::time::Duration::new(60, 0))
				.connect_lazy(pguri)?))),
				.connect_lazy(pguri)?)),
		})
	}

	pub async fn begin(&self) -> Result<Conn> {
		let pool = self.pool.lock().unwrap().clone();
		let pool = self.pool.lock_arc().await;
		let conn = Conn::new(pool.acquire().await?).await?;
		Ok(conn)
	}
}

impl Conn {
	pub async fn new (conn: PoolConnection<Postgres>) -> Result<Conn> {