]> Untitled Git - lemmy.git/blob - crates/db_schema/src/lib.rs
4799720662d0b1dd01e6b64ecc5a1832bbacd195
[lemmy.git] / crates / db_schema / src / lib.rs
1 #![recursion_limit = "256"]
2
3 #[cfg(feature = "full")]
4 #[macro_use]
5 extern crate diesel;
6 #[cfg(feature = "full")]
7 #[macro_use]
8 extern crate diesel_derive_newtype;
9
10 #[cfg(feature = "full")]
11 #[macro_use]
12 extern crate diesel_derive_enum;
13
14 // this is used in tests
15 #[cfg(feature = "full")]
16 #[macro_use]
17 extern crate diesel_migrations;
18
19 #[cfg(feature = "full")]
20 #[macro_use]
21 extern crate async_trait;
22
23 pub mod aggregates;
24 #[cfg(feature = "full")]
25 pub mod impls;
26 pub mod newtypes;
27 #[cfg(feature = "full")]
28 #[rustfmt::skip]
29 pub mod schema;
30 pub mod source;
31 #[cfg(feature = "full")]
32 pub mod traits;
33 #[cfg(feature = "full")]
34 pub mod utils;
35
36 use serde::{Deserialize, Serialize};
37 use strum_macros::{Display, EnumString};
38 #[cfg(feature = "full")]
39 use ts_rs::TS;
40
41 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
42 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
43 #[cfg_attr(
44   feature = "full",
45   ExistingTypePath = "crate::schema::sql_types::SortTypeEnum"
46 )]
47 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
48 #[cfg_attr(feature = "full", ts(export))]
49 /// The post sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
50 pub enum SortType {
51   Active,
52   Hot,
53   New,
54   Old,
55   TopDay,
56   TopWeek,
57   TopMonth,
58   TopYear,
59   TopAll,
60   MostComments,
61   NewComments,
62 }
63
64 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
65 #[cfg_attr(feature = "full", derive(TS))]
66 #[cfg_attr(feature = "full", ts(export))]
67 /// The comment sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
68 pub enum CommentSortType {
69   Hot,
70   Top,
71   New,
72   Old,
73 }
74
75 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
76 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
77 #[cfg_attr(
78   feature = "full",
79   ExistingTypePath = "crate::schema::sql_types::ListingTypeEnum"
80 )]
81 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
82 #[cfg_attr(feature = "full", ts(export))]
83 /// A listing type for post and comment list fetches.
84 pub enum ListingType {
85   /// Content from your own site, as well as all connected / federated sites.
86   All,
87   /// Content from your site only.
88   Local,
89   /// Content only from communities you've subscribed to.
90   Subscribed,
91 }
92
93 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
94 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
95 #[cfg_attr(
96   feature = "full",
97   ExistingTypePath = "crate::schema::sql_types::RegistrationModeEnum"
98 )]
99 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
100 #[cfg_attr(feature = "full", ts(export))]
101 /// The registration mode for your site. Determines what happens after a user signs up.
102 pub enum RegistrationMode {
103   /// Closed to public.
104   Closed,
105   /// Open, but pending approval of a registration application.
106   RequireApplication,
107   /// Open to all.
108   Open,
109 }
110
111 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
112 #[cfg_attr(feature = "full", derive(TS))]
113 #[cfg_attr(feature = "full", ts(export))]
114 /// The type of content returned from a search.
115 pub enum SearchType {
116   All,
117   Comments,
118   Posts,
119   Communities,
120   Users,
121   Url,
122 }
123
124 #[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
125 #[cfg_attr(feature = "full", derive(TS))]
126 #[cfg_attr(feature = "full", ts(export))]
127 /// A type / status for a community subscribe.
128 pub enum SubscribedType {
129   Subscribed,
130   NotSubscribed,
131   Pending,
132 }
133
134 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
135 #[cfg_attr(feature = "full", derive(TS))]
136 #[cfg_attr(feature = "full", ts(export))]
137 /// A list of possible types for the various modlog actions.
138 pub enum ModlogActionType {
139   All,
140   ModRemovePost,
141   ModLockPost,
142   ModFeaturePost,
143   ModRemoveComment,
144   ModRemoveCommunity,
145   ModBanFromCommunity,
146   ModAddCommunity,
147   ModTransferCommunity,
148   ModAdd,
149   ModBan,
150   ModHideCommunity,
151   AdminPurgePerson,
152   AdminPurgeCommunity,
153   AdminPurgePost,
154   AdminPurgeComment,
155 }
156
157 #[derive(
158   EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq,
159 )]
160 #[cfg_attr(feature = "full", derive(TS))]
161 #[cfg_attr(feature = "full", ts(export))]
162 /// The feature type for a post.
163 pub enum PostFeatureType {
164   #[default]
165   /// Features to the top of your site.
166   Local,
167   /// Features to the top of the community.
168   Community,
169 }