Make Rust models for database schema

This commit is contained in:
2023-01-03 16:11:43 +01:00
parent a9e300ede2
commit 60988cff24
10 changed files with 142 additions and 7 deletions

View File

@@ -0,0 +1,53 @@
use diesel::prelude::*;
use super::super::schema::{languages, langandagents};
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
#[DieselTypePath = "crate::db::schema::sql_types::Release"]
pub enum Release {
Public,
NonCommercial,
Research,
Private
}
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
#[DieselTypePath = "crate::db::schema::sql_types::Dictgenre"]
pub enum DictGenre {
General,
Learning,
Etymology,
Specialized,
Historical,
Orthography,
Terminology
}
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
#[DieselTypePath = "crate::db::schema::sql_types::Agentlanguagerelation"]
pub enum AgentLanguageRelation {
Publisher,
Author
}
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]
pub struct Language {
release: Release,
created: chrono::NaiveDateTime,
name: String,
owner: String,
targetlanguage: Vec<String>,
genre: Vec<DictGenre>,
native: Option<String>,
abstract_: Option<String>,
description: Option<String>,
rights: Option<String>,
license: Option<String>,
}
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]
#[diesel(table_name = langandagents)]
pub struct LangAndAgent {
id: i32,
agent: String,
language: String,
}