@@ -17,6 +17,8 @@ struct Article {
1717 content : String ,
1818 authorname : String ,
1919 coauthor : Option < String > ,
20+ authorage : Option < f32 > ,
21+ authorheight : Option < f64 > ,
2022}
2123
2224impl TryFrom < & pg:: Row > for Article {
@@ -28,13 +30,17 @@ impl TryFrom<&pg::Row> for Article {
2830 let content = String :: decode ( & row[ 2 ] ) ?;
2931 let authorname = String :: decode ( & row[ 3 ] ) ?;
3032 let coauthor = Option :: < String > :: decode ( & row[ 4 ] ) ?;
33+ let authorage = Option :: < f32 > :: decode ( & row[ 5 ] ) ?;
34+ let authorheight = Option :: < f64 > :: decode ( & row[ 6 ] ) ?;
3135
3236 Ok ( Self {
3337 id,
3438 title,
3539 content,
3640 authorname,
3741 coauthor,
42+ authorage,
43+ authorheight,
3844 } )
3945 }
4046}
@@ -55,7 +61,8 @@ fn read(_req: Request<()>) -> Result<Response<String>> {
5561 let address = std:: env:: var ( DB_URL_ENV ) ?;
5662 let conn = pg:: Connection :: open ( & address) ?;
5763
58- let sql = "SELECT id, title, content, authorname, coauthor FROM articletest" ;
64+ let sql =
65+ "SELECT id, title, content, authorname, coauthor, authorage, authorheight FROM articletest" ;
5966 let rowset = conn. query ( sql, & [ ] ) ?;
6067
6168 let column_summary = rowset
@@ -90,7 +97,7 @@ fn write(_req: Request<()>) -> Result<Response<String>> {
9097 let address = std:: env:: var ( DB_URL_ENV ) ?;
9198 let conn = pg:: Connection :: open ( & address) ?;
9299
93- let sql = "INSERT INTO articletest (title, content, authorname) VALUES ('aaa', 'bbb', 'ccc')" ;
100+ let sql = "INSERT INTO articletest (title, content, authorname, authorage, authorheight ) VALUES ('aaa', 'bbb', 'ccc', 1.1, 2.22 )" ;
94101 let nrow_executed = conn. execute ( sql, & [ ] ) ?;
95102
96103 println ! ( "nrow_executed: {}" , nrow_executed) ;
0 commit comments