Moving models into its own module

This commit is contained in:
Martin Voldřich 2024-08-27 15:34:43 +02:00
parent f92fe9bd65
commit 5d0b03e813
3 changed files with 34 additions and 32 deletions

1
src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod models;

View File

@ -1,42 +1,11 @@
use bcup::models::{Record, ServerConfiguration};
use futures::StreamExt;
use serde::{Deserialize, Serialize};
use surrealdb::{
engine::remote::ws::{Client, Ws},
opt::PatchOp,
sql::Thing,
Notification, Result, Surreal,
};
#[derive(Debug, Serialize, Deserialize)]
struct State {
now: String,
required: String,
}
impl State {
fn is_pending(&self) -> bool {
self.now == "pending".as_ref()
}
}
#[derive(Debug, Serialize, Deserialize)]
struct ServerConfiguration {
id: Thing,
name: String,
domain: String,
directory: String,
volume: String,
repo_password: String,
rest_password: String,
state: State,
}
#[derive(Debug, Deserialize)]
struct Record {
#[allow(dead_code)]
id: Thing,
}
#[tokio::main]
async fn main() -> surrealdb::Result<()> {
let db = Surreal::new::<Ws>("127.0.0.1:8000").await?;

32
src/models.rs Normal file
View File

@ -0,0 +1,32 @@
use serde::{Deserialize, Serialize};
use surrealdb::sql::Thing;
#[derive(Debug, Serialize, Deserialize)]
pub struct State {
pub now: String,
pub required: String,
}
impl State {
pub fn is_pending(&self) -> bool {
self.now == "pending".as_ref()
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ServerConfiguration {
pub id: Thing,
pub name: String,
pub domain: String,
pub directory: String,
pub volume: String,
pub repo_password: String,
pub rest_password: String,
pub state: State,
}
#[derive(Debug, Deserialize)]
pub struct Record {
#[allow(dead_code)]
pub id: Thing,
}