More stuff, lost a lot of progress to this shitty pc with a shitty os

This commit is contained in:
2026-08-20 16:22:35 +03:00
parent c7d2af0fd0
commit 3c904db36f
11 changed files with 319 additions and 15 deletions

View File

@@ -2,6 +2,9 @@ use diesel::pg::PgConnection;
use diesel::prelude::*;
use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations};
pub mod models;
pub mod schema;
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
pub fn init_db(database_url: &str) -> PgConnection {
@@ -14,4 +17,3 @@ pub fn init_db(database_url: &str) -> PgConnection {
connection
}

41
src/db/models.rs Normal file
View File

@@ -0,0 +1,41 @@
use chrono::NaiveDateTime;
use diesel::prelude::*;
#[derive(Queryable, Selectable)]
#[diesel(table_name = crate::db::schema::antennas)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Antenna {
pub id: i64,
pub name: String,
pub ip: String,
pub error: Option<String>,
}
#[derive(Insertable)]
#[diesel(table_name = crate::db::schema::antennas)]
pub struct NewAntenna {
pub name: String,
pub ip: String,
pub error: Option<String>,
}
#[derive(Queryable, Selectable)]
#[diesel(table_name = crate::db::schema::client_readings)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct ClientReading {
pub id: i64,
pub ip: String,
pub mac: String,
pub antenna_ip: String,
pub db_reading: i32,
pub read_at: NaiveDateTime,
}
#[derive(Insertable)]
#[diesel(table_name = crate::db::schema::client_readings)]
pub struct NewClientReading {
pub ip: String,
pub mac: String,
pub antenna_ip: String,
pub db_reading: i32,
}

23
src/db/schema.rs Normal file
View File

@@ -0,0 +1,23 @@
// @generated automatically by Diesel CLI.
diesel::table! {
antennas (id) {
id -> Int8,
name -> Text,
ip -> Text,
error -> Nullable<Text>,
}
}
diesel::table! {
client_readings (id) {
id -> Int8,
ip -> Text,
mac -> Text,
antenna_ip -> Text,
db_reading -> Int4,
read_at -> Timestamp,
}
}
diesel::allow_tables_to_appear_in_same_query!(antennas, client_readings,);