This commit is contained in:
Sofía Aritz 2024-10-14 17:38:06 +02:00
parent 1d131e790c
commit b7b938c564
Signed by: sofia
GPG key ID: 90B5116E3542B28F
4 changed files with 17 additions and 14 deletions

View file

@ -1,3 +1,4 @@
use std::fmt::{Display, Write};
use diesel::{ use diesel::{
backend::Backend, deserialize::{FromSql, FromSqlRow}, serialize::ToSql, sql_types::Text, sqlite::Sqlite backend::Backend, deserialize::{FromSql, FromSqlRow}, serialize::ToSql, sql_types::Text, sqlite::Sqlite
}; };
@ -6,16 +7,18 @@ use diesel::{
#[repr(transparent)] #[repr(transparent)]
pub struct List<V: std::fmt::Debug>(pub Vec<V>); pub struct List<V: std::fmt::Debug>(pub Vec<V>);
impl ToString for List<String> { impl Display for List<String> {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"[".to_owned() f.write_char('[')?;
+ &self f.write_str(
.0 &self
.iter() .0
.map(|v| "\"".to_owned() + &v.replace("\"", "\\\"") + "\"") .iter()
.collect::<Vec<String>>() .map(|v| "\"".to_owned() + &v.replace("\"", "\\\"") + "\"")
.join(",") .collect::<Vec<String>>()
+ "]" .join(",")
)?;
f.write_char(']')
} }
} }

View file

@ -20,7 +20,7 @@ use crate::env::database_url;
pub mod models; pub mod models;
pub mod schema; pub mod schema;
pub mod types; pub mod list;
pub fn establish_connection() -> SqliteConnection { pub fn establish_connection() -> SqliteConnection {
let url = database_url(); let url = database_url();

View file

@ -18,7 +18,7 @@ use chrono::NaiveDateTime;
use diesel::prelude::*; use diesel::prelude::*;
use crate::database::schema; use crate::database::schema;
use crate::database::types::List; use crate::database::list::List;
#[derive(Queryable, Selectable)] #[derive(Queryable, Selectable)]
#[diesel(table_name = schema::date_entries)] #[diesel(table_name = schema::date_entries)]

View file

@ -18,7 +18,7 @@ use std::env;
use std::sync::OnceLock; use std::sync::OnceLock;
use std::time::Duration; use std::time::Duration;
const REQUIRED_ENV_VARIABLES: [&'static str; 4] = [ const REQUIRED_ENV_VARIABLES: [&str; 4] = [
"IDENTITY_API_JWT_SECRET", "IDENTITY_API_JWT_SECRET",
"IDENTITY_API_ASSET_API_ENDPOINT", "IDENTITY_API_ASSET_API_ENDPOINT",
"IDENTITY_API_JWT_ALG", "IDENTITY_API_JWT_ALG",
@ -32,7 +32,7 @@ pub enum LoadEnvError {
} }
pub fn load_env() -> Result<(), LoadEnvError> { pub fn load_env() -> Result<(), LoadEnvError> {
dotenvy::dotenv().map_err(|e| LoadEnvError::DotenvyError(e))?; dotenvy::dotenv().map_err(LoadEnvError::DotenvyError)?;
for key in REQUIRED_ENV_VARIABLES { for key in REQUIRED_ENV_VARIABLES {
if env::var(key).is_err() { if env::var(key).is_err() {