1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! PostgreSQL
//! provides implementations for PostgreSQL

#[macro_use]
pub mod macros;
pub mod init;
pub mod linked_resource;
pub mod simple_resource;
pub mod simple_resource_linked;
pub(crate) mod util;

mod pool;
mod postgis;
mod queries;
mod search;

use anyhow::Error;
pub use pool::*;
use postgres_types::ToSql;
use serde_json::Value as JsonValue;
use std::collections::HashMap;
use std::fmt::Debug;
use tokio_postgres::types::Type as PsqlFieldType;

pub use self::search::{PsqlSearch, SearchCol};
pub use crate::common::ArrErr;

/// Provides a more readable format of a dynamic PostgreSQL field value
pub type PsqlField = dyn ToSql + Sync;
/// Provides a more readable format of a dynamic PostgreSQL field value with the [Send] trait
pub type PsqlFieldSend = dyn ToSql + Sync + Send;
/// Provides a more readable format of the PostgreSQL data [HashMap] definition
pub type PsqlData = HashMap<String, Box<PsqlFieldSend>>;

/// struct for JSON values
#[derive(Debug)]
pub struct PsqlJsonValue {
    /// [JsonValue]
    pub value: JsonValue,
}

impl From<tokio_postgres::Error> for ArrErr {
    fn from(err: tokio_postgres::Error) -> Self {
        let err: Error = err.into();
        psql_error!("(from) Error executing DB query: {}", err);
        ArrErr::Error(err.to_string())
    }
}
impl From<deadpool_postgres::PoolError> for ArrErr {
    fn from(err: deadpool_postgres::PoolError) -> Self {
        let err: Error = err.into();
        psql_error!("(from) Postgres pool error: {}", err);
        ArrErr::Error(err.to_string())
    }
}
impl From<deadpool_postgres::ConfigError> for ArrErr {
    fn from(err: deadpool_postgres::ConfigError) -> Self {
        let err: Error = err.into();
        psql_error!("(from) Postgres pool config error: {}", err);
        ArrErr::Error(err.to_string())
    }
}
impl From<deadpool_postgres::BuildError> for ArrErr {
    fn from(err: deadpool_postgres::BuildError) -> Self {
        let err: Error = err.into();
        psql_error!("(from) Postgres pool build error: {}", err);
        ArrErr::Error(err.to_string())
    }
}