    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

    use sqlx::AnyPool;
    use std::env;

    use crate::USERS_FILESTORE;

    #[derive(Clone)]
    pub enum UserStore {
        File(String),
        Sql(AnyPool),
       // SqlLite(SqlitePool),
        // None
    }
    impl UserStore {
        #[allow(dead_code)]
        pub async fn from_str(store: &str) -> Self {
            match store {
                "fs"|"file"|"FS"|"FILE" => {
                    println!("From File: {}",USERS_FILESTORE);
                    UserStore::File(String::from(USERS_FILESTORE))
                }
                "db"|"DB"|_ => {
                    let db_url = env::var("DATABASE_URL").unwrap_or_else(|e|{
                        eprintln!("Error env DATABASE_URL: {}",e);
                        std::process::exit(2)
                    });
                    let pool = AnyPool::connect(&db_url).await.unwrap_or_else(|e|{
                        eprintln!("Error pool DATABASE_URL: {}",e);
                        std::process::exit(2)
                    });
                    println!("From DB: {}",&db_url);
                    UserStore::Sql(pool)
                },
            }
        }
    }