pub fn insert_active_transmitter(
    conn: &PgConnection,
    worker_name: &str,
    range: RadioTypes,
    _logger: &Logger,
) -> Result<usize, MeshSimError> {
    use schema::workers;

    let rows = match range {
        RadioTypes::ShortRange => {
            use schema::active_wifi_transmitters;
            use schema::active_wifi_transmitters::dsl::*;

            workers::table
                .filter(workers::worker_name.eq(worker_name))
                .select(workers::id)
                .insert_into(active_wifi_transmitters::table)
                .into_columns(worker_id)
                .on_conflict_do_nothing()
                .execute(conn)
                .map_err(|e| {
                    let error_msg = String::from("Failed to register as active wifi transmitter");
                    MeshSimError {
                        kind: MeshSimErrorKind::SQLExecutionFailure(error_msg),
                        cause: Some(Box::new(e)),
                    }
                })?
        }
        RadioTypes::LongRange => {
            use schema::active_lora_transmitters;
            use schema::active_lora_transmitters::dsl::*;

            workers::table
                .filter(workers::worker_name.eq(worker_name))
                .select(workers::id)
                .insert_into(active_lora_transmitters::table)
                .into_columns(worker_id)
                .on_conflict_do_nothing()
                .execute(conn)
                .map_err(|e| {
                    let error_msg = String::from("Failed to register as active lora transmitter");
                    MeshSimError {
                        kind: MeshSimErrorKind::SQLExecutionFailure(error_msg),
                        cause: Some(Box::new(e)),
                    }
                })?
        }
    };

    Ok(rows)
}
///Inserts a new active transmitter into the system
Inserts a new active transmitter into the system
Inserts a new active transmitter into the system
pub fn insert_active_transmitter(
    conn: &PgConnection,
    worker_name: &str,
    range: RadioTypes,
    _logger: &Logger,
) -> Result<usize, MeshSimError> {
    use schema::workers;
    let rows = match range {
        RadioTypes::ShortRange => {
            use schema::active_wifi_transmitters;
            use schema::active_wifi_transmitters::dsl::*;
            workers::table
                .filter(workers::worker_name.eq(worker_name))
                .select(workers::id)
                .insert_into(active_wifi_transmitters::table)
                .into_columns(worker_id)
                .on_conflict_do_nothing()
                .execute(conn)
                .map_err(|e| {
                    let error_msg = String::from("Failed to register as active wifi transmitter");
                    MeshSimError {
                        kind: MeshSimErrorKind::SQLExecutionFailure(error_msg),
                        cause: Some(Box::new(e)),
                    }
                })?
        }
        RadioTypes::LongRange => {
            use schema::active_lora_transmitters;
            use schema::active_lora_transmitters::dsl::*;
            workers::table
                .filter(workers::worker_name.eq(worker_name))
                .select(workers::id)
                .insert_into(active_lora_transmitters::table)
                .into_columns(worker_id)
                .on_conflict_do_nothing()
                .execute(conn)
                .map_err(|e| {
                    let error_msg = String::from("Failed to register as active lora transmitter");
                    MeshSimError {
                        kind: MeshSimErrorKind::SQLExecutionFailure(error_msg),
                        cause: Some(Box::new(e)),
                    }
                })?
        }
    };
    Ok(rows)
}
pub fn insert_active_transmitter ( conn : & PgConnection , worker_name : & str , range : RadioTypes , _logger : & Logger , ) -> Result < usize , MeshSimError > { use schema :: workers ; let rows = match range { RadioTypes :: ShortRange => { use schema :: active_wifi_transmitters ; use schema :: active_wifi_transmitters :: dsl :: * ; workers :: table . filter ( workers :: worker_name . eq ( worker_name ) ) . select ( workers :: id ) . insert_into ( active_wifi_transmitters :: table ) . into_columns ( worker_id ) . on_conflict_do_nothing ( ) . execute ( conn ) . map_err ( | e | { let error_msg = String :: from ( " " ) ; MeshSimError { kind : MeshSimErrorKind :: SQLExecutionFailure ( error_msg ) , cause : Some ( Box :: new ( e ) ) , } } ) ? } RadioTypes :: LongRange => { use schema :: active_lora_transmitters ; use schema :: active_lora_transmitters :: dsl :: * ; workers :: table . filter ( workers :: worker_name . eq ( worker_name ) ) . select ( workers :: id ) . insert_into ( active_lora_transmitters :: table ) . into_columns ( worker_id ) . on_conflict_do_nothing ( ) . execute ( conn ) . map_err ( | e | { let error_msg = String :: from ( " " ) ; MeshSimError { kind : MeshSimErrorKind :: SQLExecutionFailure ( error_msg ) , cause : Some ( Box :: new ( e ) ) , } } ) ? } } ; Ok ( rows ) }
Inserts a new active transmitter into the system
Inserts a new active transmitter into the system
conn
&PgConnection
worker_name
&str
range
RadioTypes
_logger
&Logger