adds docs, tests unpack_gold_value

This commit is contained in:
2019-07-11 15:35:32 +02:00
parent e08cd64743
commit caa8d3fad6
4 changed files with 30 additions and 17 deletions

View File

@@ -11,17 +11,23 @@ use diesel::query_dsl::RunQueryDsl;
mod models;
mod schema;
/// The connection used
pub type DbConnection = SqliteConnection;
/// A pool of connections
pub type Pool = r2d2::Pool<ConnectionManager<DbConnection>>;
/// The result of a query on DB
pub type QueryResult<T> = Result<T, diesel::result::Error>;
/// The result of an action provided by DbApi
pub type ActionResult<R> = QueryResult<ActionStatus<R>>;
/// Return status of an API Action
///
#[derive(Serialize, Debug)]
pub struct ActionStatus<R: serde::Serialize> {
/// Has the action made changes ?
executed: bool,
pub executed: bool,
/// Response payload
response: R,
pub response: R,
}
impl ActionStatus<()> {
@@ -43,7 +49,7 @@ impl ActionStatus<()> {
/// It offers a convenient way to deal with connection
///
/// # Todo list
///
/// ```
/// struct DbApi<'q>(&'q DbConnection);
/// ::new() -> DbApi<'q> (Db finds a connection by itself, usefull for cli)
/// ::with_conn(conn) -> DbApi<'q> (uses a user-defined connection)
@@ -62,6 +68,7 @@ impl ActionStatus<()> {
/// x .sell_loot([players], [excluded_item_ids]) -> Success status (bool, player_share)
/// x .resolve_claims()
/// v .add_player(player_data)
/// ```
///
pub struct DbApi<'q>(&'q DbConnection);
@@ -201,7 +208,7 @@ impl<'q> AsPlayer<'q> {
}
}
/// Wrapper for interactions of admins with the DB.
pub struct AsAdmin<'q>(&'q DbConnection);
impl<'q> AsAdmin<'q> {
@@ -228,6 +235,8 @@ impl<'q> AsAdmin<'q> {
}
}
/// Create a connection pool and returns it.
/// Uses the DATABASE_URL environment variable (must be set)
pub fn create_pool() -> Pool {
let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
dbg!( &connspec );