]> Untitled Git - lemmy.git/blob - crates/db_schema/src/lib.rs
Use same table join code for both read and list functions (#3663)
[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 #[allow(clippy::wildcard_imports)]
30 pub mod schema;
31 #[cfg(feature = "full")]
32 pub mod aliases {
33   use crate::schema::person;
34   diesel::alias!(person as person1: Person1, person as person2: Person2);
35 }
36 pub mod source;
37 #[cfg(feature = "full")]
38 pub mod traits;
39 #[cfg(feature = "full")]
40 pub mod utils;
41
42 use serde::{Deserialize, Serialize};
43 use strum_macros::{Display, EnumString};
44 #[cfg(feature = "full")]
45 use ts_rs::TS;
46
47 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
48 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
49 #[cfg_attr(
50   feature = "full",
51   ExistingTypePath = "crate::schema::sql_types::SortTypeEnum"
52 )]
53 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
54 #[cfg_attr(feature = "full", ts(export))]
55 /// The post sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
56 pub enum SortType {
57   Active,
58   Hot,
59   New,
60   Old,
61   TopDay,
62   TopWeek,
63   TopMonth,
64   TopYear,
65   TopAll,
66   MostComments,
67   NewComments,
68   TopHour,
69   TopSixHour,
70   TopTwelveHour,
71   TopThreeMonths,
72   TopSixMonths,
73   TopNineMonths,
74   Controversial,
75 }
76
77 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
78 #[cfg_attr(feature = "full", derive(TS))]
79 #[cfg_attr(feature = "full", ts(export))]
80 /// The comment sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
81 pub enum CommentSortType {
82   Hot,
83   Top,
84   New,
85   Old,
86   Controversial,
87 }
88
89 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
90 #[cfg_attr(feature = "full", derive(TS))]
91 #[cfg_attr(feature = "full", ts(export))]
92 /// The person sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
93 pub enum PersonSortType {
94   New,
95   Old,
96   MostComments,
97   CommentScore,
98   PostScore,
99   PostCount,
100 }
101
102 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
103 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
104 #[cfg_attr(
105   feature = "full",
106   ExistingTypePath = "crate::schema::sql_types::ListingTypeEnum"
107 )]
108 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
109 #[cfg_attr(feature = "full", ts(export))]
110 /// A listing type for post and comment list fetches.
111 pub enum ListingType {
112   /// Content from your own site, as well as all connected / federated sites.
113   All,
114   /// Content from your site only.
115   Local,
116   /// Content only from communities you've subscribed to.
117   Subscribed,
118 }
119
120 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
121 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
122 #[cfg_attr(
123   feature = "full",
124   ExistingTypePath = "crate::schema::sql_types::RegistrationModeEnum"
125 )]
126 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
127 #[cfg_attr(feature = "full", ts(export))]
128 /// The registration mode for your site. Determines what happens after a user signs up.
129 pub enum RegistrationMode {
130   /// Closed to public.
131   Closed,
132   /// Open, but pending approval of a registration application.
133   RequireApplication,
134   /// Open to all.
135   Open,
136 }
137
138 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
139 #[cfg_attr(feature = "full", derive(TS))]
140 #[cfg_attr(feature = "full", ts(export))]
141 /// The type of content returned from a search.
142 pub enum SearchType {
143   All,
144   Comments,
145   Posts,
146   Communities,
147   Users,
148   Url,
149 }
150
151 #[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
152 #[cfg_attr(feature = "full", derive(TS))]
153 #[cfg_attr(feature = "full", ts(export))]
154 /// A type / status for a community subscribe.
155 pub enum SubscribedType {
156   Subscribed,
157   NotSubscribed,
158   Pending,
159 }
160
161 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
162 #[cfg_attr(feature = "full", derive(TS))]
163 #[cfg_attr(feature = "full", ts(export))]
164 /// A list of possible types for the various modlog actions.
165 pub enum ModlogActionType {
166   All,
167   ModRemovePost,
168   ModLockPost,
169   ModFeaturePost,
170   ModRemoveComment,
171   ModRemoveCommunity,
172   ModBanFromCommunity,
173   ModAddCommunity,
174   ModTransferCommunity,
175   ModAdd,
176   ModBan,
177   ModHideCommunity,
178   AdminPurgePerson,
179   AdminPurgeCommunity,
180   AdminPurgePost,
181   AdminPurgeComment,
182 }
183
184 #[derive(
185   EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq,
186 )]
187 #[cfg_attr(feature = "full", derive(TS))]
188 #[cfg_attr(feature = "full", ts(export))]
189 /// The feature type for a post.
190 pub enum PostFeatureType {
191   #[default]
192   /// Features to the top of your site.
193   Local,
194   /// Features to the top of the community.
195   Community,
196 }