@@ -5,42 +5,61 @@ use crate::schema::*;
55use diesel:: QueryResult ;
66use crate :: models:: common:: * ;
77
8- #[ derive( Debug , Clone , Queryable , Selectable ) ]
8+ /// Struct representing a row in table `todo`
9+ #[ derive( Debug , Clone , Queryable , Selectable , QueryableByName ) ]
910#[ diesel( table_name=todo, primary_key( id) ) ]
1011pub struct Todo {
12+ /// Field representing column `id`
1113 pub id : i32 ,
14+ /// Field representing column `text`
1215 pub text : String ,
16+ /// Field representing column `completed`
1317 pub completed : bool ,
18+ /// Field representing column `created_at`
1419 pub created_at : chrono:: DateTime < chrono:: Utc > ,
20+ /// Field representing column `updated_at`
1521 pub updated_at : chrono:: DateTime < chrono:: Utc > ,
1622}
1723
24+ /// Create Struct for a row in table `todo` for [`Todo`]
1825#[ derive( Debug , Clone , Insertable ) ]
1926#[ diesel( table_name=todo) ]
2027pub struct CreateTodo {
28+ /// Field representing column `id`
2129 pub id : i32 ,
30+ /// Field representing column `text`
2231 pub text : String ,
32+ /// Field representing column `completed`
2333 pub completed : bool ,
34+ /// Field representing column `created_at`
2435 pub created_at : chrono:: DateTime < chrono:: Utc > ,
36+ /// Field representing column `updated_at`
2537 pub updated_at : chrono:: DateTime < chrono:: Utc > ,
2638}
2739
28- #[ derive( Debug , Clone , AsChangeset , Default ) ]
40+ /// Update Struct for a row in table `todo` for [`Todo`]
41+ #[ derive( Debug , Clone , AsChangeset , PartialEq , Default ) ]
2942#[ diesel( table_name=todo) ]
3043pub struct UpdateTodo {
44+ /// Field representing column `text`
3145 pub text : Option < String > ,
46+ /// Field representing column `completed`
3247 pub completed : Option < bool > ,
48+ /// Field representing column `created_at`
3349 pub created_at : Option < chrono:: DateTime < chrono:: Utc > > ,
50+ /// Field representing column `updated_at`
3451 pub updated_at : Option < chrono:: DateTime < chrono:: Utc > > ,
3552}
3653
3754impl Todo {
55+ /// Insert a new row into `todo` with a given [`CreateTodo`]
3856 pub fn create ( db : & mut ConnectionType , item : & CreateTodo ) -> QueryResult < Self > {
3957 use crate :: schema:: todo:: dsl:: * ;
4058
4159 insert_into ( todo) . values ( item) . get_result :: < Self > ( db)
4260 }
4361
62+ /// Get a row from `todo`, identified by the primary key
4463 pub fn read ( db : & mut ConnectionType , param_id : i32 ) -> QueryResult < Self > {
4564 use crate :: schema:: todo:: dsl:: * ;
4665
@@ -65,12 +84,14 @@ impl Todo {
6584 } )
6685 }
6786
87+ /// Update a row in `todo`, identified by the primary key with [`UpdateTodo`]
6888 pub fn update ( db : & mut ConnectionType , param_id : i32 , item : & UpdateTodo ) -> QueryResult < Self > {
6989 use crate :: schema:: todo:: dsl:: * ;
7090
7191 diesel:: update ( todo. filter ( id. eq ( param_id) ) ) . set ( item) . get_result ( db)
7292 }
7393
94+ /// Delete a row in `todo`, identified by the primary key
7495 pub fn delete ( db : & mut ConnectionType , param_id : i32 ) -> QueryResult < usize > {
7596 use crate :: schema:: todo:: dsl:: * ;
7697
0 commit comments