aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--license-generator/src/database.rs13
-rw-r--r--license-generator/src/errors.rs2
-rw-r--r--license-generator/src/lib.rs1
-rw-r--r--license-generator/src/purchaser.rs2
4 files changed, 17 insertions, 1 deletions
diff --git a/license-generator/src/database.rs b/license-generator/src/database.rs
new file mode 100644
index 0000000..28673c4
--- /dev/null
+++ b/license-generator/src/database.rs
@@ -0,0 +1,13 @@
+use std::env;
+
+use mysql;
+
+use errors::*;
+
+fn get_database_connection() -> Result<mysql::PooledConn> {
+ let connection_url = env::var("DATABASE_URL")?;
+ let pool = mysql::Pool::new_manual(10, 50, connection_url)?;
+ let cx = pool.get_conn()?;
+
+ Ok(cx)
+}
diff --git a/license-generator/src/errors.rs b/license-generator/src/errors.rs
index 7eb9eda..29f25ca 100644
--- a/license-generator/src/errors.rs
+++ b/license-generator/src/errors.rs
@@ -2,6 +2,8 @@ use mysql;
error_chain! {
foreign_links {
+ EnvVar(::std::env::VarError);
+
MySql(mysql::error::Error);
}
}
diff --git a/license-generator/src/lib.rs b/license-generator/src/lib.rs
index fd1bfa8..e129d17 100644
--- a/license-generator/src/lib.rs
+++ b/license-generator/src/lib.rs
@@ -5,5 +5,6 @@ extern crate rand;
extern crate sha1;
+mod database;
mod errors;
mod purchaser;
diff --git a/license-generator/src/purchaser.rs b/license-generator/src/purchaser.rs
index 2a7727c..3e9656e 100644
--- a/license-generator/src/purchaser.rs
+++ b/license-generator/src/purchaser.rs
@@ -29,7 +29,7 @@ impl<'a> Purchaser<'a> {
self.secret = Some(digest);
}
- fn insert(&self, cx: &mut mysql::Conn) -> Result<()> {
+ fn insert(&self, cx: &mut mysql::PooledConn) -> Result<()> {
let mut tx = cx.start_transaction(
false, // consistent_snapshot
None, // isolation_level