This commit is contained in:
2025-06-17 14:46:48 +02:00
parent 5a4bbc5297
commit 1089196226
8 changed files with 80 additions and 35 deletions

8
.gitignore vendored
View File

@@ -20,8 +20,8 @@ Cargo.lock
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.env
.env.*
!.env.example
!.env.*.example
.env
.env.*
!.env.example
!.env.*.example
# Ignore the .env file that contains sensitive information

View File

@@ -1,11 +1,15 @@
{
"cSpell.words": [
"dotenv",
"Herstellung",
"Kochen",
"MSVC",
"Quelle",
"Raffination",
"rustc",
"serde",
"Stück",
"VARCHAR",
"Verwendung"
]
}

View File

@@ -5,10 +5,11 @@ edition = "2024"
publish = ["merlin"]
description = "Utility functions to read environment with fallback and values from a file"
license = "MIT"
repository = "ssh://git@gitea.merlinserver.de:2222/Stefan/merlin_env_helper.git"
repository = "ssh://git@gitea.merlinserver.de:2222/Stefan/no-man-sky-wiki.git"
[dependencies]
diesel = { version= "2.2.10", features = ["serde_json", "postgres", "uuid"]}
dotenv = "0.15.0"
env_logger = "0.11.8"
log = "0.4.27"
merlin_env_helper = { version = "0.2.0", registry = "merlin" }
@@ -16,3 +17,5 @@ regex = "1.11.1"
reqwest = {version="0.12.15", features=["blocking"]}
#scraper = "0.23.1"
select = "0.6.1"
serde_json = "1.0.140"
uuid = "1.17.0"

View File

@@ -5,7 +5,7 @@ CREATE TABLE "icon"(
"url" VARCHAR(512),
"width" INT4,
"height" INT4,
"state" JSON
"state" JSONB
);
CREATE TABLE "resource"(
@@ -14,7 +14,7 @@ CREATE TABLE "resource"(
"title" VARCHAR(255) NOT NULL,
"url" VARCHAR(512),
"icon" UUID,
"state" JSON,
"state" JSONB,
FOREIGN KEY ("icon") REFERENCES "icon"("id")
);
@@ -23,7 +23,7 @@ CREATE TABLE "recipe"(
"resource" UUID NOT NULL,
"recipe_type" VARCHAR(50) NOT NULL,
"duration" INT4 NOT NULL,
"state" JSON,
"state" JSONB,
FOREIGN KEY ("resource") REFERENCES "resource"("id")
);
@@ -31,7 +31,7 @@ CREATE TABLE "ingredient"(
"id" UUID NOT NULL PRIMARY KEY,
"resource" UUID NOT NULL,
"quantity" INT4 NOT NULL,
"state" JSON,
"state" JSONB,
"recipe" UUID NOT NULL,
FOREIGN KEY ("resource") REFERENCES "resource"("id"),
FOREIGN KEY ("recipe") REFERENCES "recipe"("id")

View File

@@ -1,2 +1,32 @@
pub mod models;
pub mod schema;
use diesel::{Connection, PgConnection};
use merlin_env_helper::{EnvKey, get_env_value};
pub use models::*;
fn _read_key() -> String {
get_env_value(&EnvKey::secure_key("DATABASE_URL", "DATABASE_URL_FILE"))
.expect("Failed to read DATABASE_URL")
}
pub fn establish_connection() -> PgConnection {
let database_url = _read_key();
PgConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
}
pub fn test() {
let conn = &mut establish_connection();
use diesel::prelude::*;
use crate::db::schema::icon::dsl::*;
let results: Vec<DbIcon> = icon
.select(DbIcon::as_select())
.load(conn)
.expect("Error loading icons");
for resource in results {
println!("Found resource: {:?}", resource);
}
}

View File

@@ -2,46 +2,54 @@
#![allow(unused)]
#![allow(clippy::all)]
use diesel::{
prelude::Queryable,
sql_types::{Json, Uuid},
};
#[derive(Queryable, Debug)]
pub struct RowIcon {
use diesel::{pg::Pg, prelude::*};
use uuid::Uuid;
#[derive(Queryable, Selectable, Debug)]
#[diesel(table_name = crate::db::schema::icon)]
#[diesel(check_for_backend(Pg))]
pub struct DbIcon {
pub id: Uuid,
pub name: String,
pub content_type: Option<String>,
pub url: Option<String>,
pub width: Option<i32>,
pub height: Option<i32>,
pub state: Option<Json>,
pub state: Option<serde_json::Value>,
}
#[derive(Queryable, Debug)]
pub struct RowIngredient {
#[derive(Queryable, Selectable, Debug)]
#[diesel(table_name = crate::db::schema::ingredient)]
#[diesel(check_for_backend(Pg))]
pub struct DbIngredient {
pub id: Uuid,
pub resource: Uuid,
pub quantity: i32,
pub state: Option<Json>,
pub state: Option<serde_json::Value>,
pub recipe: Uuid,
}
#[derive(Queryable, Debug)]
pub struct RowRecipe {
#[derive(Queryable, Selectable, Debug)]
#[diesel(table_name = crate::db::schema::recipe)]
#[diesel(check_for_backend(Pg))]
pub struct DbRecipe {
pub id: Uuid,
pub resource: Uuid,
pub recipe_type: String,
pub duration: i32,
pub state: Option<Json>,
pub state: Option<serde_json::Value>,
}
#[derive(Queryable, Debug)]
pub struct RowResource {
#[derive(Queryable, Selectable, Debug)]
#[diesel(table_name = crate::db::schema::resource)]
#[diesel(check_for_backend(Pg))]
pub struct DbResource {
pub id: Uuid,
pub name: String,
pub title: String,
pub url: Option<String>,
pub icon: Option<Uuid>,
pub state: Option<Json>,
pub state: Option<serde_json::Value>,
}

View File

@@ -11,7 +11,7 @@ diesel::table! {
url -> Nullable<Varchar>,
width -> Nullable<Int4>,
height -> Nullable<Int4>,
state -> Nullable<Json>,
state -> Nullable<Jsonb>,
}
}
@@ -20,7 +20,7 @@ diesel::table! {
id -> Uuid,
resource -> Uuid,
quantity -> Int4,
state -> Nullable<Json>,
state -> Nullable<Jsonb>,
recipe -> Uuid,
}
}
@@ -32,7 +32,7 @@ diesel::table! {
#[max_length = 50]
recipe_type -> Varchar,
duration -> Int4,
state -> Nullable<Json>,
state -> Nullable<Jsonb>,
}
}
@@ -46,7 +46,7 @@ diesel::table! {
#[max_length = 512]
url -> Nullable<Varchar>,
icon -> Nullable<Uuid>,
state -> Nullable<Json>,
state -> Nullable<Jsonb>,
}
}
@@ -55,9 +55,4 @@ diesel::joinable!(ingredient -> resource (resource));
diesel::joinable!(recipe -> resource (resource));
diesel::joinable!(resource -> icon (icon));
diesel::allow_tables_to_appear_in_same_query!(
icon,
ingredient,
recipe,
resource,
);
diesel::allow_tables_to_appear_in_same_query!(icon, ingredient, recipe, resource,);

View File

@@ -3,12 +3,17 @@ mod parse;
mod types;
use std::{fs::File, io::Read};
use dotenv::dotenv;
use parse::parse;
use crate::db::test;
fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
env_logger::init();
let html = read("test_mordit.html")?;
parse(&html);
test();
Ok(())
}