Make Rust models for database schema
This commit is contained in:
2
src/db/mod.rs
Normal file
2
src/db/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod models;
|
||||
pub mod schema;
|
||||
53
src/db/models/languages.rs
Normal file
53
src/db/models/languages.rs
Normal 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,
|
||||
}
|
||||
3
src/db/models/mod.rs
Normal file
3
src/db/models/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod users;
|
||||
pub mod languages;
|
||||
pub mod words;
|
||||
16
src/db/models/users.rs
Normal file
16
src/db/models/users.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use diesel::prelude::*;
|
||||
use super::super::schema::{userfollows, users};
|
||||
|
||||
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]
|
||||
pub struct User {
|
||||
pub id: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]
|
||||
#[diesel(table_name = userfollows)]
|
||||
pub struct UserFollow {
|
||||
pub id: i32,
|
||||
pub follower: String,
|
||||
pub following: String,
|
||||
}
|
||||
56
src/db/models/words.rs
Normal file
56
src/db/models/words.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use diesel::prelude::*;
|
||||
use super::super::schema::{wordrelation, words};
|
||||
|
||||
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
|
||||
#[DieselTypePath = "crate::db::schema::sql_types::Wordrelationship"]
|
||||
pub enum WordRelationship {
|
||||
Definition,
|
||||
Related
|
||||
}
|
||||
|
||||
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
|
||||
#[DieselTypePath = "crate::db::schema::sql_types::Partofspeech"]
|
||||
pub enum PartOfSpeech {
|
||||
Adjective,
|
||||
Adposition,
|
||||
Adverb,
|
||||
Auxilliary,
|
||||
CoordConj,
|
||||
Determiner,
|
||||
Interjection,
|
||||
Noun,
|
||||
Numeral,
|
||||
Particle,
|
||||
Pronoun,
|
||||
ProperNoun,
|
||||
Punctuation,
|
||||
SubjConj,
|
||||
Symbol,
|
||||
Verb,
|
||||
Other
|
||||
}
|
||||
|
||||
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]
|
||||
struct Word {
|
||||
norm: String,
|
||||
native: Option<String>,
|
||||
lemma: Option<String>,
|
||||
language: String,
|
||||
partofspeech: PartOfSpeech,
|
||||
audio: Option<String>,
|
||||
video: Option<String>,
|
||||
image: Option<String>,
|
||||
description: Option<String>,
|
||||
etymology: Option<String>,
|
||||
lusage: Option<String>,
|
||||
morphology: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]
|
||||
#[diesel(table_name = wordrelation)]
|
||||
struct WordRelation {
|
||||
id: i32,
|
||||
wordsource: String,
|
||||
wordtarget: String,
|
||||
relationship: WordRelationship,
|
||||
}
|
||||
@@ -42,12 +42,12 @@ diesel::table! {
|
||||
languages (name) {
|
||||
name -> Varchar,
|
||||
native -> Nullable<Varchar>,
|
||||
relese -> Release,
|
||||
release -> Release,
|
||||
targetlanguage -> Array<Nullable<Text>>,
|
||||
genre -> Array<Nullable<Dictgenre>>,
|
||||
#[sql_name = "abstract"]
|
||||
abstract_ -> Nullable<Text>,
|
||||
created -> Nullable<Timestamptz>,
|
||||
created -> Timestamp,
|
||||
description -> Nullable<Text>,
|
||||
rights -> Nullable<Text>,
|
||||
license -> Nullable<Text>,
|
||||
@@ -1,3 +1,5 @@
|
||||
mod db;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user