Introduce a get! macro to avoid some code duplication

This commit is contained in:
Bat
2018-06-18 14:44:23 +01:00
parent 3c9210a0ed
commit 94af0b9a7d
12 changed files with 24 additions and 78 deletions
+1 -7
View File
@@ -110,13 +110,7 @@ impl User {
.into_iter().nth(0).unwrap()
}
pub fn get(conn: &PgConnection, id: i32) -> Option<User> {
users::table.filter(users::id.eq(id))
.limit(1)
.load::<User>(conn)
.expect("Error loading user by id")
.into_iter().nth(0)
}
get!(users);
pub fn count_local(conn: &PgConnection) -> usize {
users::table.filter(users::instance_id.eq(Instance::local_id(conn)))