I have no idea what I'm dong
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
use crate::models::{Driver, NewDriver};
|
||||
use common::CommonDriver;
|
||||
use diesel::prelude::*;
|
||||
use diesel::{prelude::*, query_builder::SqlQuery, sql_query};
|
||||
|
||||
pub fn listdrivers(connection: &mut PgConnection) {
|
||||
use crate::schema::drivers::dsl::*;
|
||||
let queury = drivers.load::<Driver>(connection).expect("KANKER");
|
||||
for driver in queury {
|
||||
println!("{} {}", driver.name, driver.address);
|
||||
pub fn listdrivers(connection: &mut PgConnection) -> Vec<CommonDriver> {
|
||||
let query = sql_query("SELECT * FROM drivers WHERE id = 10").load::<Driver>(connection);
|
||||
let mut drivers: Vec<CommonDriver> = Vec::new();
|
||||
for driver in query.unwrap() {
|
||||
drivers.push(CommonDriver {
|
||||
id: driver.id,
|
||||
name: driver.name,
|
||||
address: driver.address,
|
||||
});
|
||||
}
|
||||
return drivers;
|
||||
}
|
||||
|
||||
pub fn addriver(connection: &mut PgConnection, new_driver: NewDriver) {
|
||||
@@ -31,4 +36,3 @@ pub fn get_driver(connection: &mut PgConnection, driver_id: i32) -> CommonDriver
|
||||
address: String::from(&driver.address),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ pub struct AutoIssuedTicket<'a> {
|
||||
}
|
||||
|
||||
//Drivers
|
||||
#[derive(Queryable, AsChangeset, Identifiable)]
|
||||
#[derive(Queryable, AsChangeset, Identifiable, QueryableByName)]
|
||||
#[table_name = "drivers"]
|
||||
pub struct Driver {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
@@ -87,8 +88,8 @@ pub struct NewDriver<'a> {
|
||||
}
|
||||
|
||||
//Vehicles
|
||||
#[derive(Queryable)]
|
||||
#[diesel(belongs_to(Driver))]
|
||||
#[derive(Queryable, QueryableByName)]
|
||||
#[diesel(belongs_to(Driver), table_name = vehicles)]
|
||||
pub struct Vehicle {
|
||||
pub model: Option<String>,
|
||||
pub color: Option<String>,
|
||||
|
||||
Reference in New Issue
Block a user