TyPe MiSmAtCh pGdAtE eXpEcTeD StRiNg
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use diesel::prelude::*;
|
||||
use diesel::pg::data_types::PgDate;
|
||||
use common::CommonDriver;
|
||||
use crate::models::{Driver,NewDriver};
|
||||
|
||||
pub fn listdrivers(connection: &mut PgConnection)
|
||||
@@ -19,3 +21,19 @@ pub fn addriver(connection: &mut PgConnection, new_driver: NewDriver){
|
||||
.execute(connection)
|
||||
.expect("Couldn't insert new driver :)");
|
||||
}
|
||||
|
||||
pub fn get_driver(connection: &mut PgConnection, driver_id: i32) -> CommonDriver {
|
||||
use crate::schema::drivers::dsl::*;
|
||||
let driver = &mut drivers
|
||||
.filter(id.eq(driver_id))
|
||||
.limit(1)
|
||||
.load::<Driver>(connection)
|
||||
.expect("no drivers :(")[0];
|
||||
return CommonDriver {
|
||||
id: driver.id,
|
||||
name: String::from(&driver.name),
|
||||
address: String::from(&driver.address),
|
||||
reg_date: &driver.regdate,
|
||||
birthdate: String::from(&driver.birthdate),
|
||||
};
|
||||
}
|
||||
@@ -83,8 +83,7 @@ pub struct Driver {
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = drivers)]
|
||||
pub
|
||||
struct NewDriver<'a> {
|
||||
pub struct NewDriver<'a> {
|
||||
pub id: i32,
|
||||
pub name: &'a str,
|
||||
pub address: &'a str,
|
||||
|
||||
Reference in New Issue
Block a user