1
/// Holds the data needed by Canyon when the user
2
/// application it's running.
3
///
4
/// Takes care about provide a namespace where retrieve the
5
/// database credentials in only one place
6
///
7
/// Takes care about track what data structures Canyon
8
/// should be managing
9
///
10
/// Takes care about the queries that Canyon has to execute
11
/// in order to perform the migrations
12
pub mod migrations;
13

            
14
extern crate canyon_connection;
15
extern crate canyon_crud;
16
extern crate canyon_entities;
17

            
18
mod constants;
19

            
20
use canyon_connection::lazy_static::lazy_static;
21
use std::{collections::HashMap, sync::Mutex};
22

            
23
lazy_static! {
24
    pub static ref QUERIES_TO_EXECUTE: Mutex<HashMap<String, Vec<String>>> =
25
        Mutex::new(HashMap::new());
26
    pub static ref CM_QUERIES_TO_EXECUTE: Mutex<HashMap<String, Vec<String>>> =
27
        Mutex::new(HashMap::new());
28
}
29

            
30
/// Stores a newly generated SQL statement from the migrations into the register
31
pub fn save_migrations_query_to_execute(stmt: String, ds_name: &str) {
32
    if QUERIES_TO_EXECUTE.lock().unwrap().contains_key(ds_name) {
33
        QUERIES_TO_EXECUTE
34
            .lock()
35
            .unwrap()
36
            .get_mut(ds_name)
37
            .unwrap()
38
            .push(stmt);
39
    } else {
40
        QUERIES_TO_EXECUTE
41
            .lock()
42
            .unwrap()
43
            .insert(ds_name.to_owned(), vec![stmt]);
44
    }
45
}