Moving models into its own module
This commit is contained in:
parent
f92fe9bd65
commit
5d0b03e813
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod models;
|
33
src/main.rs
33
src/main.rs
@ -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
32
src/models.rs
Normal 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,
|
||||
}
|
Loading…
Reference in New Issue
Block a user