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

View file

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

View file

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

View file

@ -18,7 +18,7 @@ use std::env;
use std::sync::OnceLock;
use std::time::Duration;
const REQUIRED_ENV_VARIABLES: [&'static str; 4] = [
const REQUIRED_ENV_VARIABLES: [&str; 4] = [
"IDENTITY_API_JWT_SECRET",
"IDENTITY_API_ASSET_API_ENDPOINT",
"IDENTITY_API_JWT_ALG",
@ -32,7 +32,7 @@ pub enum 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 {
if env::var(key).is_err() {