aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/lib.rs')
-rw-r--r--rust/src/lib.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
new file mode 100644
index 00000000..679b9ed3
--- /dev/null
+++ b/rust/src/lib.rs
@@ -0,0 +1,18 @@
+
+#[macro_use]
+extern crate diesel;
+extern crate dotenv;
+
+use diesel::prelude::*;
+use diesel::pg::PgConnection;
+use dotenv::dotenv;
+use std::env;
+
+pub fn establish_connection() -> PgConnection {
+ dotenv().ok();
+
+ let database_url = env::var("DATABASE_URL")
+ .expect("DATABASE_URL must be set");
+ PgConnection::establish(&database_url)
+ .expect(&format!("Error connecting to {}", database_url))
+}