Refactored database handling

This commit is contained in:
2021-05-18 18:44:17 +02:00
parent a89068047b
commit d25e039751
6 changed files with 58 additions and 50 deletions

@ -1,11 +1,7 @@
use crate::database;
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 {
@ -26,10 +22,10 @@ pub fn endpoint(endpoint: &str, input: json::JsonValue) -> json::JsonValue {
}
pub fn echo(input: json::JsonValue) -> json::JsonValue {
let backend = get_backend();
let backend = database::client();
let mut output = input.clone();
match backend {
BackendClient::Postgres(mut client) => {
database::Client::Postgres(mut client) => {
let res = client.query("SELECT * FROM test", &[]).unwrap();
for row in res {
let val: i32 = row.get(0);