My schemas:
diesel::table! {
farm_room (id) {
id -> Int8,
added_at -> Nullable<Timestamptz>,
modified_at -> Nullable<Timestamptz>,
#[max_length = 200]
name -> Varchar,
control_mode -> Int2,
is_control_tolerance_enabled -> Bool,
added_by_id -> Nullable<Uuid>,
farm_id -> Nullable<Int8>,
modified_by_id -> Nullable<Uuid>,
tight_control -> Bool,
last_control -> Nullable<Timestamptz>,
}
}
diesel::table! {
farm_device (id) {
id -> Int8,
added_at -> Nullable<Timestamptz>,
modified_at -> Nullable<Timestamptz>,
#[max_length = 20]
name -> Nullable<Varchar>,
#[max_length = 10]
serial_number -> Nullable<Varchar>,
#[max_length = 8]
device_type -> Varchar,
mac -> Nullable<Int8>,
is_active -> Bool,
added_by_id -> Nullable<Uuid>,
farm_id -> Nullable<Int8>,
modified_by_id -> Nullable<Uuid>,
}
}
diesel::table! {
farm_node (id) {
id -> Int8,
added_at -> Nullable<Timestamptz>,
modified_at -> Nullable<Timestamptz>,
#[max_length = 20]
name -> Varchar,
is_primary -> Bool,
sampling_period -> Nullable<Interval>,
added_by_id -> Nullable<Uuid>,
modified_by_id -> Nullable<Uuid>,
room_id -> Nullable<Int8>,
device_id -> Nullable<Int8>,
}
}
I want to define a function to build query to retrieve Node
s which belong to a Room
, but its associated device
must be active, so I have:
impl Room {
pub fn active_nodes_query(&self) -> farm_node::BoxedQuery<'static, diesel::pg::Pg> {
use crate::schema::farm_node::dsl::*;
let x = farm_node
.select(Node::as_select())
.inner_join(farm_device::table)
.filter(device_id.is_not_null())
.filter(farm_device::is_active.eq(true))
.filter(room_id.eq(self.id))
.into_boxed();
x
}
}
But I don't know what to declare as return type for active_nodes_query
. farm_node::BoxedQuery
is not correct.