Database pool working
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
use json;
|
||||
use r2d2::{ManageConnection, Pool, PooledConnection};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use crate::{get_backend, BackendClient};
|
||||
|
||||
static ENDPOINTS: [(&str, fn(json::JsonValue) -> json::JsonValue); 1] = [("echo", echo)];
|
||||
static ENDPOINTS: [(&str, fn(json::JsonValue) -> json::JsonValue); 1] = [
|
||||
("echo", echo)
|
||||
];
|
||||
|
||||
pub fn is_valid_endpoint(endpoint: &str) -> bool {
|
||||
for (name, _func) in &ENDPOINTS {
|
||||
@ -21,5 +26,16 @@ pub fn endpoint(endpoint: &str, input: json::JsonValue) -> json::JsonValue {
|
||||
}
|
||||
|
||||
pub fn echo(input: json::JsonValue) -> json::JsonValue {
|
||||
input
|
||||
let backend = get_backend();
|
||||
let mut output = input.clone();
|
||||
match backend {
|
||||
BackendClient::Postgres(mut client) => {
|
||||
let res = client.query("SELECT * FROM test", &[]).unwrap();
|
||||
for row in res {
|
||||
let val: i32 = row.get(0);
|
||||
output["database"] = val.into();
|
||||
}
|
||||
}
|
||||
}
|
||||
output
|
||||
}
|
||||
|
Reference in New Issue
Block a user