From f2fad5fbba01f77cf33793d86e8e90d9e9ded1ee Mon Sep 17 00:00:00 2001 From: Vinod J M Date: Sun, 2 Oct 2022 13:15:41 +0530 Subject: [PATCH] v0.02 --- backend/.env | 1 + backend/entity/Cargo.toml | 1 + backend/entity/src/entities/book.rs | 68 +++++++++++++++++++ backend/entity/src/entities/book_author.rs | 32 +++++++++ backend/entity/src/entities/book_person.rs | 32 +++++++++ backend/entity/src/entities/book_place.rs | 32 +++++++++ backend/entity/src/entities/book_subject.rs | 32 +++++++++ backend/entity/src/entities/book_time.rs | 32 +++++++++ backend/entity/src/entities/mod.rs | 10 +++ backend/entity/src/entities/prelude.rs | 8 +++ backend/entity/src/lib.rs | 4 +- backend/entity/src/post.rs | 26 ------- .../src/m20220101_000001_create_table.rs | 2 +- 13 files changed, 252 insertions(+), 28 deletions(-) create mode 100644 backend/.env create mode 100644 backend/entity/src/entities/book.rs create mode 100644 backend/entity/src/entities/book_author.rs create mode 100644 backend/entity/src/entities/book_person.rs create mode 100644 backend/entity/src/entities/book_place.rs create mode 100644 backend/entity/src/entities/book_subject.rs create mode 100644 backend/entity/src/entities/book_time.rs create mode 100644 backend/entity/src/entities/mod.rs create mode 100644 backend/entity/src/entities/prelude.rs delete mode 100644 backend/entity/src/post.rs diff --git a/backend/.env b/backend/.env new file mode 100644 index 0000000..c8deed0 --- /dev/null +++ b/backend/.env @@ -0,0 +1 @@ +DATABASE_URL="sqlite:./sqlite.db?mode=rwc" diff --git a/backend/entity/Cargo.toml b/backend/entity/Cargo.toml index 45ca30b..981e6fd 100644 --- a/backend/entity/Cargo.toml +++ b/backend/entity/Cargo.toml @@ -10,6 +10,7 @@ path = "src/lib.rs" [dependencies] serde = { version = "1", features = ["derive"] } +chrono = "0.4" [dependencies.sea-orm] version = "^0.9.2" # sea-orm version diff --git a/backend/entity/src/entities/book.rs b/backend/entity/src/entities/book.rs new file mode 100644 index 0000000..6d9b4ba --- /dev/null +++ b/backend/entity/src/entities/book.rs @@ -0,0 +1,68 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "book")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub open_library_key: String, + pub title: String, + pub edition_count: i32, + pub first_publish_year: i32, + pub median_page_count: i32, + pub goodread_id: String, + pub description: String, + pub cover: String, + pub location: String, + pub time_added: String, + pub rating: i32, + pub comments: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::book_author::Entity")] + BookAuthor, + #[sea_orm(has_many = "super::book_person::Entity")] + BookPerson, + #[sea_orm(has_many = "super::book_place::Entity")] + BookPlace, + #[sea_orm(has_many = "super::book_subject::Entity")] + BookSubject, + #[sea_orm(has_many = "super::book_time::Entity")] + BookTime, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::BookAuthor.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::BookPerson.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::BookPlace.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::BookSubject.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::BookTime.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/backend/entity/src/entities/book_author.rs b/backend/entity/src/entities/book_author.rs new file mode 100644 index 0000000..1983217 --- /dev/null +++ b/backend/entity/src/entities/book_author.rs @@ -0,0 +1,32 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "book_author")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub author_name: String, + pub book_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::book::Entity", + from = "Column::BookId", + to = "super::book::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Book, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Book.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/backend/entity/src/entities/book_person.rs b/backend/entity/src/entities/book_person.rs new file mode 100644 index 0000000..cf589e6 --- /dev/null +++ b/backend/entity/src/entities/book_person.rs @@ -0,0 +1,32 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "book_person")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub person: String, + pub book_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::book::Entity", + from = "Column::BookId", + to = "super::book::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Book, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Book.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/backend/entity/src/entities/book_place.rs b/backend/entity/src/entities/book_place.rs new file mode 100644 index 0000000..bb5a5d0 --- /dev/null +++ b/backend/entity/src/entities/book_place.rs @@ -0,0 +1,32 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "book_place")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub place: String, + pub book_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::book::Entity", + from = "Column::BookId", + to = "super::book::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Book, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Book.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/backend/entity/src/entities/book_subject.rs b/backend/entity/src/entities/book_subject.rs new file mode 100644 index 0000000..fa9d114 --- /dev/null +++ b/backend/entity/src/entities/book_subject.rs @@ -0,0 +1,32 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "book_subject")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub subject: String, + pub book_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::book::Entity", + from = "Column::BookId", + to = "super::book::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Book, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Book.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/backend/entity/src/entities/book_time.rs b/backend/entity/src/entities/book_time.rs new file mode 100644 index 0000000..9151198 --- /dev/null +++ b/backend/entity/src/entities/book_time.rs @@ -0,0 +1,32 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "book_time")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub time: String, + pub book_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::book::Entity", + from = "Column::BookId", + to = "super::book::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Book, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Book.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/backend/entity/src/entities/mod.rs b/backend/entity/src/entities/mod.rs new file mode 100644 index 0000000..97bb3c0 --- /dev/null +++ b/backend/entity/src/entities/mod.rs @@ -0,0 +1,10 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +pub mod prelude; + +pub mod book; +pub mod book_author; +pub mod book_person; +pub mod book_place; +pub mod book_subject; +pub mod book_time; diff --git a/backend/entity/src/entities/prelude.rs b/backend/entity/src/entities/prelude.rs new file mode 100644 index 0000000..aa79f6a --- /dev/null +++ b/backend/entity/src/entities/prelude.rs @@ -0,0 +1,8 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.2 + +pub use super::book::Entity as Book; +pub use super::book_author::Entity as BookAuthor; +pub use super::book_person::Entity as BookPerson; +pub use super::book_place::Entity as BookPlace; +pub use super::book_subject::Entity as BookSubject; +pub use super::book_time::Entity as BookTime; diff --git a/backend/entity/src/lib.rs b/backend/entity/src/lib.rs index e8b6291..5bdcb1c 100644 --- a/backend/entity/src/lib.rs +++ b/backend/entity/src/lib.rs @@ -1 +1,3 @@ -pub mod post; +mod entities; +pub use entities::*; + diff --git a/backend/entity/src/post.rs b/backend/entity/src/post.rs deleted file mode 100644 index 76d7819..0000000 --- a/backend/entity/src/post.rs +++ /dev/null @@ -1,26 +0,0 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.3.2 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "posts")] -pub struct Model { - #[sea_orm(primary_key)] - #[serde(skip_deserializing)] - pub id: i32, - pub title: String, - #[sea_orm(column_type = "Text")] - pub text: String, -} - -#[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation {} - -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/backend/migration/src/m20220101_000001_create_table.rs b/backend/migration/src/m20220101_000001_create_table.rs index 6fdc479..0b9db09 100644 --- a/backend/migration/src/m20220101_000001_create_table.rs +++ b/backend/migration/src/m20220101_000001_create_table.rs @@ -93,7 +93,7 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(BookAuthor::Table) + .table(BookPerson::Table) .if_not_exists() .col( ColumnDef::new(BookPerson::Id)