Migrate to sqlx
This commit is contained in:
parent
bd44dc3183
commit
f3d08aab80
19 changed files with 1488 additions and 588 deletions
src/db
|
@ -1,68 +1,37 @@
|
|||
use crate::db::model_utils::Period;
|
||||
use diesel::sql_types::Binary;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::schema::*;
|
||||
use crate::types::EmgauwaUid;
|
||||
|
||||
#[derive(Debug, Serialize, Identifiable, Queryable)]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Relay {
|
||||
#[serde(skip)]
|
||||
pub id: i32,
|
||||
pub id: i64,
|
||||
// TODO
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Identifiable, Queryable, Clone)]
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
pub struct Schedule {
|
||||
#[serde(skip)]
|
||||
pub id: i32,
|
||||
pub id: i64,
|
||||
#[serde(rename(serialize = "id"))]
|
||||
pub uid: EmgauwaUid,
|
||||
pub name: String,
|
||||
pub periods: Periods,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::schedules)]
|
||||
pub struct NewSchedule<'a> {
|
||||
pub uid: &'a EmgauwaUid,
|
||||
pub name: &'a str,
|
||||
pub periods: &'a Periods,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, AsExpression, FromSqlRow, PartialEq, Clone)]
|
||||
#[diesel(sql_type = Binary)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
||||
pub struct Periods(pub Vec<Period>);
|
||||
|
||||
#[derive(Debug, Serialize, Identifiable, Queryable, Clone)]
|
||||
#[diesel(table_name = crate::db::schema::tags)]
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
pub struct Tag {
|
||||
pub id: i32,
|
||||
pub id: i64,
|
||||
pub tag: String,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::tags)]
|
||||
pub struct NewTag<'a> {
|
||||
pub tag: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Associations, Identifiable)]
|
||||
#[diesel(belongs_to(Relay))]
|
||||
#[diesel(belongs_to(Schedule))]
|
||||
#[diesel(belongs_to(Tag))]
|
||||
#[diesel(table_name = crate::db::schema::junction_tag)]
|
||||
pub struct JunctionTag {
|
||||
pub id: i32,
|
||||
pub tag_id: i32,
|
||||
pub relay_id: Option<i32>,
|
||||
pub schedule_id: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::junction_tag)]
|
||||
pub struct NewJunctionTag {
|
||||
pub tag_id: i32,
|
||||
pub relay_id: Option<i32>,
|
||||
pub schedule_id: Option<i32>,
|
||||
pub id: i64,
|
||||
pub tag_id: i64,
|
||||
pub relay_id: Option<i64>,
|
||||
pub schedule_id: Option<i64>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue