Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 2192a5f

Browse files
committed
Derive appropriate macros on models
1 parent 2955a09 commit 2192a5f

6 files changed

Lines changed: 21 additions & 29 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ derive_more = "0.99"
2121
dotenv = "0.15"
2222
reqwest = { version = "0.11.1", features = ["json"] }
2323
tokio = "1.0"
24+
time = {version="0.2", features=["serde", "std"]}
2425

25-
tokio-postgres = {version = "0.7", features = ["with-uuid-0_8"]}
26+
sqlx = {version = "0.5.1", features=["postgres", "macros", "uuid", "time", "runtime-tokio-rustls"]}
2627

2728
[[bin]]
2829
name = "yank_config"

src/.models.rs.swp

12 KB
Binary file not shown.

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl Config {
164164
}
165165

166166
// I should _really_ use a different version of this for PlantArchetypes and PossessionArchetypes ...
167-
pub type ArchetypeHandle = usize;
167+
pub type ArchetypeHandle = u32;
168168

169169
lazy_static::lazy_static! {
170170
pub static ref CONFIG: Config = {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![recursion_limit = "256"]
22
#![feature(try_trait)]
3+
#![feature(trivial_bounds)]
34
#![warn(missing_docs)]
45

56
use humantime::{format_rfc3339, parse_rfc3339};

src/models.rs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::config::{ArchetypeHandle, PlantArchetype};
22
use crate::*;
33
use serde::Serialize;
4-
use std::time::SystemTime;
5-
use tokio_postgres::Client as PgClient;
6-
use tokio_postgres::error::Error as SqlError;
4+
use time::PrimitiveDateTime;
5+
use sqlx::types::Type;
6+
use sqlx::FromRow;
77

88

9-
#[derive(Clone, Debug, Serialize)]
9+
#[derive(Clone, Debug, Serialize, FromRow)]
1010
pub struct Hacksteader {
1111
pub user_id: String,
1212
pub profile: Profile,
@@ -15,53 +15,42 @@ pub struct Hacksteader {
1515
pub gotchis: Vec<Possessed<possess::Gotchi>>,
1616
}
1717

18-
#[derive(Debug, Clone, Serialize)]
18+
#[derive(Debug, Clone, Serialize, Type)]
1919
pub struct Tile {
20-
pub acquired: SystemTime,
20+
pub acquired: PrimitiveDateTime,
2121
pub plant: Option<Plant>,
2222
pub id: uuid::Uuid,
2323
pub steader: String,
2424
}
2525

26-
#[derive(Clone, Debug, Serialize)]
26+
#[derive(Clone, Debug, Serialize, Type)]
2727
pub struct Profile {
2828
/// Indicates when this Hacksteader first joined the elite community.
29-
pub joined: SystemTime,
30-
pub last_active: SystemTime,
31-
pub last_farm: SystemTime,
29+
pub joined: PrimitiveDateTime,
30+
pub last_active: PrimitiveDateTime,
31+
pub last_farm: PrimitiveDateTime,
3232
/// This is not an uuid::Uuid because it's actually the steader id of the person who owns this Profile
3333
pub id: String,
34-
pub xp: u64,
34+
pub xp: u32,
3535
}
3636

37-
#[derive(Debug, Clone, Serialize)]
37+
#[derive(Debug, Clone, Serialize, Type)]
3838
pub struct Plant {
39-
pub xp: u64,
39+
pub xp: u32,
4040
pub until_yield: f32,
4141
pub craft: Option<Craft>,
4242
pub pedigree: Vec<possess::seed::SeedGrower>,
4343
pub archetype_handle: ArchetypeHandle,
4444
}
4545

46-
#[derive(Debug, Clone, Serialize)]
46+
#[derive(Debug, Clone, Serialize, Type)]
4747
pub struct Craft {
4848
pub until_finish: f32,
4949
pub total_cycles: f32,
5050
pub destroys_plant: bool,
5151
pub makes: ArchetypeHandle,
5252
}
5353

54-
impl Hacksteader {
55-
pub async fn insert_to_sql(&self, client: &PgClient) -> Result<(), SqlError> {
56-
57-
Ok(())
58-
}
59-
60-
pub async fn update_in_sql(&self, client: &PgClient) -> Result<(), SqlError> {
61-
Ok(())
62-
}
63-
}
64-
6554
impl std::ops::Deref for Plant {
6655
type Target = PlantArchetype;
6756

src/possess/seed.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{config, AttributeParseError, Item, CONFIG};
33
use config::{ArchetypeHandle, ArchetypeKind};
44
use rusoto_dynamodb::AttributeValue;
55
use serde::{Deserialize, Serialize};
6+
use sqlx::types::Type as PgType;
67

78
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)]
89
pub struct Seed {
@@ -17,10 +18,10 @@ impl Possessable for Seed {
1718
PossessionKind::Seed(self)
1819
}
1920
}
20-
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)]
21+
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, PgType)]
2122
pub struct SeedGrower {
2223
pub id: String,
23-
pub generations: u64,
24+
pub generations: u32,
2425
}
2526
impl SeedGrower {
2627
pub fn new(id: String, generations: u64) -> Self {

0 commit comments

Comments
 (0)