Introduce a find_by! macro to avoid some code duplication

This commit is contained in:
Bat
2018-06-18 14:37:49 +01:00
parent 36bf2e114c
commit 3c9210a0ed
7 changed files with 22 additions and 56 deletions
+1 -7
View File
@@ -125,13 +125,7 @@ impl User {
.len()
}
pub fn find_by_email(conn: &PgConnection, email: String) -> Option<User> {
users::table.filter(users::email.eq(email))
.limit(1)
.load::<User>(conn)
.expect("Error loading user by email")
.into_iter().nth(0)
}
find_by!(users, find_by_email, email as String);
pub fn find_by_name(conn: &PgConnection, username: String, instance_id: i32) -> Option<User> {
users::table.filter(users::username.eq(username))