v0.02
This commit is contained in:
1
backend/.env
Normal file
1
backend/.env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DATABASE_URL="sqlite:./sqlite.db?mode=rwc"
|
||||||
@@ -10,6 +10,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
chrono = "0.4"
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
[dependencies.sea-orm]
|
||||||
version = "^0.9.2" # sea-orm version
|
version = "^0.9.2" # sea-orm version
|
||||||
|
|||||||
68
backend/entity/src/entities/book.rs
Normal file
68
backend/entity/src/entities/book.rs
Normal file
@@ -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<super::book_author::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::BookAuthor.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::book_person::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::BookPerson.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::book_place::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::BookPlace.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::book_subject::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::BookSubject.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::book_time::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::BookTime.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
32
backend/entity/src/entities/book_author.rs
Normal file
32
backend/entity/src/entities/book_author.rs
Normal file
@@ -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<super::book::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Book.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
32
backend/entity/src/entities/book_person.rs
Normal file
32
backend/entity/src/entities/book_person.rs
Normal file
@@ -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<super::book::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Book.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
32
backend/entity/src/entities/book_place.rs
Normal file
32
backend/entity/src/entities/book_place.rs
Normal file
@@ -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<super::book::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Book.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
32
backend/entity/src/entities/book_subject.rs
Normal file
32
backend/entity/src/entities/book_subject.rs
Normal file
@@ -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<super::book::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Book.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
32
backend/entity/src/entities/book_time.rs
Normal file
32
backend/entity/src/entities/book_time.rs
Normal file
@@ -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<super::book::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Book.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
10
backend/entity/src/entities/mod.rs
Normal file
10
backend/entity/src/entities/mod.rs
Normal file
@@ -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;
|
||||||
8
backend/entity/src/entities/prelude.rs
Normal file
8
backend/entity/src/entities/prelude.rs
Normal file
@@ -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;
|
||||||
@@ -1 +1,3 @@
|
|||||||
pub mod post;
|
mod entities;
|
||||||
|
pub use entities::*;
|
||||||
|
|
||||||
|
|||||||
@@ -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 {}
|
|
||||||
@@ -93,7 +93,7 @@ impl MigrationTrait for Migration {
|
|||||||
manager
|
manager
|
||||||
.create_table(
|
.create_table(
|
||||||
Table::create()
|
Table::create()
|
||||||
.table(BookAuthor::Table)
|
.table(BookPerson::Table)
|
||||||
.if_not_exists()
|
.if_not_exists()
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(BookPerson::Id)
|
ColumnDef::new(BookPerson::Id)
|
||||||
|
|||||||
Reference in New Issue
Block a user