mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2025-02-20 16:46:16 +00:00
Add a list_by! macro
This commit is contained in:
parent
e074af57ff
commit
ddd840d31d
1 changed files with 12 additions and 0 deletions
|
@ -12,6 +12,18 @@ macro_rules! find_by {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! list_by {
|
||||
($table:ident, $fn:ident, $($col:ident as $type:ident),+) => {
|
||||
/// Try to find a $table with a given $col
|
||||
pub fn $fn(conn: &PgConnection, $($col: $type),+) -> Vec<Self> {
|
||||
$table::table
|
||||
$(.filter($table::$col.eq($col)))+
|
||||
.load::<Self>(conn)
|
||||
.expect("Error loading $table by $col")
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! get {
|
||||
($table:ident) => {
|
||||
pub fn get(conn: &PgConnection, id: i32) -> Option<Self> {
|
||||
|
|
Loading…
Reference in a new issue