From 5c51a9bdafda4987ab7da52b816e01ea6b56502d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 11 Mar 2021 11:14:41 +0100 Subject: Endpoint configuration as Map This patch rewrites the endpoint configuration format to be a map. The problem here is, that a list of endpoints cannot easily be used with layered configuration, where a part of the configuration lives in the XDG config home of the user and the rest lives in the repository. With this patch, the endpoints are configured with a map instead of an array, which makes it less complicated to overwrite. The name of an endpoint is now the key in the map. A type `EndpointName` was introduced to take advantage of strong typing. Thus, the patch touches a bit more code to adapt to the new type in use. Signed-off-by: Matthias Beyer Tested-by: Matthias Beyer --- src/db/models/endpoint.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/db') diff --git a/src/db/models/endpoint.rs b/src/db/models/endpoint.rs index 73009f6..d7a7986 100644 --- a/src/db/models/endpoint.rs +++ b/src/db/models/endpoint.rs @@ -13,6 +13,7 @@ use anyhow::Result; use diesel::prelude::*; use diesel::PgConnection; +use crate::config::EndpointName; use crate::schema::endpoints; use crate::schema::endpoints::*; @@ -29,8 +30,8 @@ struct NewEndpoint<'a> { } impl Endpoint { - pub fn create_or_fetch(database_connection: &PgConnection, ep_name: &str) -> Result { - let new_ep = NewEndpoint { name: ep_name }; + pub fn create_or_fetch(database_connection: &PgConnection, ep_name: &EndpointName) -> Result { + let new_ep = NewEndpoint { name: ep_name.as_ref() }; diesel::insert_into(endpoints::table) .values(&new_ep) @@ -38,7 +39,7 @@ impl Endpoint { .execute(database_connection)?; dsl::endpoints - .filter(name.eq(ep_name)) + .filter(name.eq(ep_name.as_ref())) .first::(database_connection) .map_err(Error::from) } -- cgit v1.2.3