-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
authors = ["clux <[email protected]>"] | ||
name = "dieselpgsslcrate" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
log = "0.4.*" | ||
env_logger = "0.6" | ||
uuid = { version = "0.7.*", features = ["v4"] } | ||
diesel = { version = "1.4.*", features = ["postgres", "uuid", "r2d2"] } | ||
openssl = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use diesel::pg::PgConnection; | ||
use diesel::r2d2::{ConnectionManager, Pool}; | ||
use std::sync::Arc; | ||
|
||
pub(crate) type ConnectionPool = Arc<Pool<ConnectionManager<PgConnection>>>; | ||
|
||
pub(crate) fn create_database_pool(url: &str, size: u32) -> ConnectionPool { | ||
let manager = ConnectionManager::<PgConnection>::new(url); | ||
let pool = Pool::builder() | ||
.max_size(size) | ||
.build(manager) | ||
.expect("Error creating a database pool"); | ||
|
||
Arc::new(pool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#[macro_use] extern crate diesel; | ||
extern crate openssl; | ||
use std::env; | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let _db = { | ||
let url = std::env::var("DATABASE_URL") | ||
.unwrap_or("postgres://localhost?connect_timeout=1&sslmode=require".into()); | ||
let size = env::var("DATABASE_POOL_SIZE") | ||
.map(|val| { | ||
val.parse::<u32>() | ||
.expect("Error converting DATABASE_POOL_SIZE variable into u32") | ||
}) | ||
.unwrap_or_else(|_| 5); | ||
|
||
crate::db::create_database_pool(&url, size) | ||
}; | ||
|
||
{ | ||
let mut input = String::new(); | ||
std::io::stdin().read_line(&mut input).unwrap(); | ||
} | ||
} | ||
|
||
pub(crate) mod db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
table! { | ||
room (id) { | ||
id -> Uuid, | ||
data -> Text, | ||
} | ||
} |