flix_db/entity/content/
libraries.rs

1//! Library entity
2
3use flix_model::id::LibraryId;
4
5use seamantic::model::path::PathBytes;
6
7use sea_orm::{
8	ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
9	EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
10};
11
12/// The database representation of a library media folder
13#[derive(Debug, Clone, DeriveEntityModel)]
14#[sea_orm(table_name = "flix_libraries")]
15pub struct Model {
16	/// The library's ID
17	#[sea_orm(primary_key, auto_increment = false)]
18	pub id: LibraryId,
19	/// The library's directory
20	pub directory: PathBytes,
21}
22
23impl ActiveModelBehavior for ActiveModel {}
24
25/// Relation
26#[derive(Debug, EnumIter, DeriveRelation)]
27pub enum Relation {
28	/// All collections in this library
29	#[sea_orm(has_many = "super::collections::Entity")]
30	Collections,
31	#[sea_orm(has_many = "super::movies::Entity")]
32	/// All movies in this library
33	Movies,
34	#[sea_orm(has_many = "super::shows::Entity")]
35	/// All shows in this library
36	Shows,
37	#[sea_orm(has_many = "super::seasons::Entity")]
38	/// All seasons in this library
39	Seasons,
40	#[sea_orm(has_many = "super::episodes::Entity")]
41	/// All episodes in this library
42	Episodes,
43}
44
45impl Related<super::collections::Entity> for Entity {
46	fn to() -> RelationDef {
47		Relation::Collections.def()
48	}
49}
50
51impl Related<super::movies::Entity> for Entity {
52	fn to() -> RelationDef {
53		Relation::Movies.def()
54	}
55}
56
57impl Related<super::shows::Entity> for Entity {
58	fn to() -> RelationDef {
59		Relation::Shows.def()
60	}
61}
62
63impl Related<super::seasons::Entity> for Entity {
64	fn to() -> RelationDef {
65		Relation::Seasons.def()
66	}
67}
68
69impl Related<super::episodes::Entity> for Entity {
70	fn to() -> RelationDef {
71		Relation::Episodes.def()
72	}
73}