Add a list_by! macro
This commit is contained in:
		
							parent
							
								
									e074af57ff
								
							
						
					
					
						commit
						ddd840d31d
					
				| @ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user