Update
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -20,8 +20,8 @@ Cargo.lock
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# 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.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
!.env.*.example
|
!.env.*.example
|
||||||
# Ignore the .env file that contains sensitive information
|
# Ignore the .env file that contains sensitive information
|
||||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -1,11 +1,15 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
|
"dotenv",
|
||||||
"Herstellung",
|
"Herstellung",
|
||||||
"Kochen",
|
"Kochen",
|
||||||
|
"MSVC",
|
||||||
"Quelle",
|
"Quelle",
|
||||||
"Raffination",
|
"Raffination",
|
||||||
|
"rustc",
|
||||||
"serde",
|
"serde",
|
||||||
"Stück",
|
"Stück",
|
||||||
|
"VARCHAR",
|
||||||
"Verwendung"
|
"Verwendung"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ edition = "2024"
|
|||||||
publish = ["merlin"]
|
publish = ["merlin"]
|
||||||
description = "Utility functions to read environment with fallback and values from a file"
|
description = "Utility functions to read environment with fallback and values from a file"
|
||||||
license = "MIT"
|
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]
|
[dependencies]
|
||||||
diesel = { version= "2.2.10", features = ["serde_json", "postgres", "uuid"]}
|
diesel = { version= "2.2.10", features = ["serde_json", "postgres", "uuid"]}
|
||||||
|
dotenv = "0.15.0"
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
merlin_env_helper = { version = "0.2.0", registry = "merlin" }
|
merlin_env_helper = { version = "0.2.0", registry = "merlin" }
|
||||||
@@ -16,3 +17,5 @@ regex = "1.11.1"
|
|||||||
reqwest = {version="0.12.15", features=["blocking"]}
|
reqwest = {version="0.12.15", features=["blocking"]}
|
||||||
#scraper = "0.23.1"
|
#scraper = "0.23.1"
|
||||||
select = "0.6.1"
|
select = "0.6.1"
|
||||||
|
serde_json = "1.0.140"
|
||||||
|
uuid = "1.17.0"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ CREATE TABLE "icon"(
|
|||||||
"url" VARCHAR(512),
|
"url" VARCHAR(512),
|
||||||
"width" INT4,
|
"width" INT4,
|
||||||
"height" INT4,
|
"height" INT4,
|
||||||
"state" JSON
|
"state" JSONB
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE "resource"(
|
CREATE TABLE "resource"(
|
||||||
@@ -14,7 +14,7 @@ CREATE TABLE "resource"(
|
|||||||
"title" VARCHAR(255) NOT NULL,
|
"title" VARCHAR(255) NOT NULL,
|
||||||
"url" VARCHAR(512),
|
"url" VARCHAR(512),
|
||||||
"icon" UUID,
|
"icon" UUID,
|
||||||
"state" JSON,
|
"state" JSONB,
|
||||||
FOREIGN KEY ("icon") REFERENCES "icon"("id")
|
FOREIGN KEY ("icon") REFERENCES "icon"("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ CREATE TABLE "recipe"(
|
|||||||
"resource" UUID NOT NULL,
|
"resource" UUID NOT NULL,
|
||||||
"recipe_type" VARCHAR(50) NOT NULL,
|
"recipe_type" VARCHAR(50) NOT NULL,
|
||||||
"duration" INT4 NOT NULL,
|
"duration" INT4 NOT NULL,
|
||||||
"state" JSON,
|
"state" JSONB,
|
||||||
FOREIGN KEY ("resource") REFERENCES "resource"("id")
|
FOREIGN KEY ("resource") REFERENCES "resource"("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ CREATE TABLE "ingredient"(
|
|||||||
"id" UUID NOT NULL PRIMARY KEY,
|
"id" UUID NOT NULL PRIMARY KEY,
|
||||||
"resource" UUID NOT NULL,
|
"resource" UUID NOT NULL,
|
||||||
"quantity" INT4 NOT NULL,
|
"quantity" INT4 NOT NULL,
|
||||||
"state" JSON,
|
"state" JSONB,
|
||||||
"recipe" UUID NOT NULL,
|
"recipe" UUID NOT NULL,
|
||||||
FOREIGN KEY ("resource") REFERENCES "resource"("id"),
|
FOREIGN KEY ("resource") REFERENCES "resource"("id"),
|
||||||
FOREIGN KEY ("recipe") REFERENCES "recipe"("id")
|
FOREIGN KEY ("recipe") REFERENCES "recipe"("id")
|
||||||
|
|||||||
@@ -1,2 +1,32 @@
|
|||||||
pub mod models;
|
pub mod models;
|
||||||
|
pub mod schema;
|
||||||
|
use diesel::{Connection, PgConnection};
|
||||||
|
use merlin_env_helper::{EnvKey, get_env_value};
|
||||||
pub use models::*;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,46 +2,54 @@
|
|||||||
|
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![allow(clippy::all)]
|
#![allow(clippy::all)]
|
||||||
use diesel::{
|
|
||||||
prelude::Queryable,
|
|
||||||
sql_types::{Json, Uuid},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Queryable, Debug)]
|
use diesel::{pg::Pg, prelude::*};
|
||||||
pub struct RowIcon {
|
|
||||||
|
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 id: Uuid,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub content_type: Option<String>,
|
pub content_type: Option<String>,
|
||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
pub width: Option<i32>,
|
pub width: Option<i32>,
|
||||||
pub height: Option<i32>,
|
pub height: Option<i32>,
|
||||||
pub state: Option<Json>,
|
pub state: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Debug)]
|
#[derive(Queryable, Selectable, Debug)]
|
||||||
pub struct RowIngredient {
|
#[diesel(table_name = crate::db::schema::ingredient)]
|
||||||
|
#[diesel(check_for_backend(Pg))]
|
||||||
|
pub struct DbIngredient {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub resource: Uuid,
|
pub resource: Uuid,
|
||||||
pub quantity: i32,
|
pub quantity: i32,
|
||||||
pub state: Option<Json>,
|
pub state: Option<serde_json::Value>,
|
||||||
pub recipe: Uuid,
|
pub recipe: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Debug)]
|
#[derive(Queryable, Selectable, Debug)]
|
||||||
pub struct RowRecipe {
|
#[diesel(table_name = crate::db::schema::recipe)]
|
||||||
|
#[diesel(check_for_backend(Pg))]
|
||||||
|
pub struct DbRecipe {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub resource: Uuid,
|
pub resource: Uuid,
|
||||||
pub recipe_type: String,
|
pub recipe_type: String,
|
||||||
pub duration: i32,
|
pub duration: i32,
|
||||||
pub state: Option<Json>,
|
pub state: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Debug)]
|
#[derive(Queryable, Selectable, Debug)]
|
||||||
pub struct RowResource {
|
#[diesel(table_name = crate::db::schema::resource)]
|
||||||
|
#[diesel(check_for_backend(Pg))]
|
||||||
|
pub struct DbResource {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
pub icon: Option<Uuid>,
|
pub icon: Option<Uuid>,
|
||||||
pub state: Option<Json>,
|
pub state: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ diesel::table! {
|
|||||||
url -> Nullable<Varchar>,
|
url -> Nullable<Varchar>,
|
||||||
width -> Nullable<Int4>,
|
width -> Nullable<Int4>,
|
||||||
height -> Nullable<Int4>,
|
height -> Nullable<Int4>,
|
||||||
state -> Nullable<Json>,
|
state -> Nullable<Jsonb>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ diesel::table! {
|
|||||||
id -> Uuid,
|
id -> Uuid,
|
||||||
resource -> Uuid,
|
resource -> Uuid,
|
||||||
quantity -> Int4,
|
quantity -> Int4,
|
||||||
state -> Nullable<Json>,
|
state -> Nullable<Jsonb>,
|
||||||
recipe -> Uuid,
|
recipe -> Uuid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ diesel::table! {
|
|||||||
#[max_length = 50]
|
#[max_length = 50]
|
||||||
recipe_type -> Varchar,
|
recipe_type -> Varchar,
|
||||||
duration -> Int4,
|
duration -> Int4,
|
||||||
state -> Nullable<Json>,
|
state -> Nullable<Jsonb>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ diesel::table! {
|
|||||||
#[max_length = 512]
|
#[max_length = 512]
|
||||||
url -> Nullable<Varchar>,
|
url -> Nullable<Varchar>,
|
||||||
icon -> Nullable<Uuid>,
|
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!(recipe -> resource (resource));
|
||||||
diesel::joinable!(resource -> icon (icon));
|
diesel::joinable!(resource -> icon (icon));
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
diesel::allow_tables_to_appear_in_same_query!(icon, ingredient, recipe, resource,);
|
||||||
icon,
|
|
||||||
ingredient,
|
|
||||||
recipe,
|
|
||||||
resource,
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -3,12 +3,17 @@ mod parse;
|
|||||||
mod types;
|
mod types;
|
||||||
use std::{fs::File, io::Read};
|
use std::{fs::File, io::Read};
|
||||||
|
|
||||||
|
use dotenv::dotenv;
|
||||||
use parse::parse;
|
use parse::parse;
|
||||||
|
|
||||||
|
use crate::db::test;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let html = read("test_mordit.html")?;
|
let html = read("test_mordit.html")?;
|
||||||
parse(&html);
|
parse(&html);
|
||||||
|
test();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user