summaryrefslogtreecommitdiff
path: root/server/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/db.rs')
-rw-r--r--server/src/db.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/server/src/db.rs b/server/src/db.rs
new file mode 100644
index 0000000..8cc4d1f
--- /dev/null
+++ b/server/src/db.rs
@@ -0,0 +1,20 @@
+use crate::errors::AppError;
+
+use sqlx::postgres::PgPool;
+
+static mut CONNECTION: Option<PgPool> = None;
+
+pub async fn setup() -> Result<(), AppError> {
+ let database_url =
+ std::env::var("DATABASE_URL").expect("Define `DATABASE_URL` environment variable.");
+
+ unsafe {
+ CONNECTION = Some(PgPool::connect(&database_url).await?);
+ }
+
+ Ok(())
+}
+
+pub unsafe fn get_client() -> Option<&'static PgPool> {
+ CONNECTION.as_ref()
+}