TyPe MiSmAtCh pGdAtE eXpEcTeD StRiNg

This commit is contained in:
LinlyBoi
2022-12-23 19:35:08 +00:00
parent 99ec37991e
commit bcf3ec0d8c
6 changed files with 42 additions and 6 deletions

View File

@@ -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),
};
}

View File

@@ -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,