mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add server
This commit is contained in:
parent
775f3ffe90
commit
d0c25531d3
27 changed files with 1725 additions and 3 deletions
39
musicus_server/src/database/mod.rs
Normal file
39
musicus_server/src/database/mod.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use anyhow::Result;
|
||||
use diesel::r2d2;
|
||||
use diesel::PgConnection;
|
||||
|
||||
pub mod ensembles;
|
||||
pub use ensembles::*;
|
||||
|
||||
pub mod instruments;
|
||||
pub use instruments::*;
|
||||
|
||||
pub mod persons;
|
||||
pub use persons::*;
|
||||
|
||||
pub mod recordings;
|
||||
pub use recordings::*;
|
||||
|
||||
pub mod users;
|
||||
pub use users::*;
|
||||
|
||||
pub mod works;
|
||||
pub use works::*;
|
||||
|
||||
mod schema;
|
||||
|
||||
/// A pool of connections to the database.
|
||||
pub type DbPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>;
|
||||
|
||||
/// One database connection from the connection pool.
|
||||
pub type DbConn = r2d2::PooledConnection<r2d2::ConnectionManager<PgConnection>>;
|
||||
|
||||
/// Create a connection pool for a database. This will look for the database URL in the
|
||||
/// "MUSICUS_DATABASE_URL" environment variable and fail, if that is not set.
|
||||
pub fn connect() -> Result<DbPool> {
|
||||
let url = std::env::var("MUSICUS_DATABASE_URL")?;
|
||||
let manager = r2d2::ConnectionManager::<PgConnection>::new(url);
|
||||
let pool = r2d2::Pool::new(manager)?;
|
||||
|
||||
Ok(pool)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue