aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-03-21 19:31:14 +0000
committerFuwn <[email protected]>2021-03-21 19:31:14 +0000
commitde8b01889999ae28b9c054787e005a5387d343e6 (patch)
tree61f85dd8f54a759c23af6f719dc55fd50455165e /src/utils
parentformat: Use single space for `user_properties` migration (diff)
downloadwhirl-de8b01889999ae28b9c054787e005a5387d343e6.tar.xz
whirl-de8b01889999ae28b9c054787e005a5387d343e6.zip
format: `utils` module as directory
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/db.rs16
-rw-r--r--src/utils/mod.rs2
-rw-r--r--src/utils/web.rs7
3 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/db.rs b/src/utils/db.rs
new file mode 100644
index 0000000..adc11d3
--- /dev/null
+++ b/src/utils/db.rs
@@ -0,0 +1,16 @@
+use sqlx::sqlite::{SqlitePool, SqlitePoolOptions};
+use std::env;
+
+pub async fn get_pool() -> Result<SqlitePool, Box<dyn std::error::Error>> {
+ let pool = SqlitePoolOptions::new()
+ .max_connections(20)
+ .connect(&env::var("DATABASE_URL")?)
+ .await?;
+
+ debug!(
+ "connected to database at url '{}'",
+ &env::var("DATABASE_URL")?
+ );
+
+ Ok(pool)
+}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
new file mode 100644
index 0000000..1f54796
--- /dev/null
+++ b/src/utils/mod.rs
@@ -0,0 +1,2 @@
+pub mod db;
+pub mod web;
diff --git a/src/utils/web.rs b/src/utils/web.rs
new file mode 100644
index 0000000..a834648
--- /dev/null
+++ b/src/utils/web.rs
@@ -0,0 +1,7 @@
+pub fn _is_double_crnl(window: &[u8]) -> bool {
+ window.len() >= 4
+ && (window[0] == '\r' as u8)
+ && (window[1] == '\n' as u8)
+ && (window[2] == '\r' as u8)
+ && (window[3] == '\n' as u8)
+}