diff --git a/Cargo.toml b/Cargo.toml index eb30baf..2b20d74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,9 @@ derive_more = "0.99" dotenv = "0.15" reqwest = { version = "0.11.1", features = ["json"] } tokio = "1.0" +time = {version="0.2", features=["serde", "std"]} -tokio-postgres = {version = "0.7", features = ["with-uuid-0_8"]} +sqlx = {version = "0.5.1", features=["postgres", "macros", "uuid", "time", "runtime-tokio-rustls"]} [[bin]] name = "yank_config" diff --git a/src/.models.rs.swp b/src/.models.rs.swp new file mode 100644 index 0000000..fbda342 Binary files /dev/null and b/src/.models.rs.swp differ diff --git a/src/config.rs b/src/config.rs index ccc13e3..bcc2d1f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -164,7 +164,7 @@ impl Config { } // I should _really_ use a different version of this for PlantArchetypes and PossessionArchetypes ... -pub type ArchetypeHandle = usize; +pub type ArchetypeHandle = u32; lazy_static::lazy_static! { pub static ref CONFIG: Config = { diff --git a/src/lib.rs b/src/lib.rs index 43d6cd9..a183235 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![recursion_limit = "256"] #![feature(try_trait)] +#![feature(trivial_bounds)] #![warn(missing_docs)] use humantime::{format_rfc3339, parse_rfc3339}; diff --git a/src/models.rs b/src/models.rs index 6509cfd..e79299e 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,12 +1,12 @@ use crate::config::{ArchetypeHandle, PlantArchetype}; use crate::*; use serde::Serialize; -use std::time::SystemTime; -use tokio_postgres::Client as PgClient; -use tokio_postgres::error::Error as SqlError; +use time::PrimitiveDateTime; +use sqlx::types::Type; +use sqlx::FromRow; -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, Serialize, FromRow)] pub struct Hacksteader { pub user_id: String, pub profile: Profile, @@ -15,35 +15,35 @@ pub struct Hacksteader { pub gotchis: Vec>, } -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, Type)] pub struct Tile { - pub acquired: SystemTime, + pub acquired: PrimitiveDateTime, pub plant: Option, pub id: uuid::Uuid, pub steader: String, } -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, Serialize, Type)] pub struct Profile { /// Indicates when this Hacksteader first joined the elite community. - pub joined: SystemTime, - pub last_active: SystemTime, - pub last_farm: SystemTime, + pub joined: PrimitiveDateTime, + pub last_active: PrimitiveDateTime, + pub last_farm: PrimitiveDateTime, /// This is not an uuid::Uuid because it's actually the steader id of the person who owns this Profile pub id: String, - pub xp: u64, + pub xp: u32, } -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, Type)] pub struct Plant { - pub xp: u64, + pub xp: u32, pub until_yield: f32, pub craft: Option, pub pedigree: Vec, pub archetype_handle: ArchetypeHandle, } -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, Type)] pub struct Craft { pub until_finish: f32, pub total_cycles: f32, @@ -51,17 +51,6 @@ pub struct Craft { pub makes: ArchetypeHandle, } -impl Hacksteader { - pub async fn insert_to_sql(&self, client: &PgClient) -> Result<(), SqlError> { - - Ok(()) - } - - pub async fn update_in_sql(&self, client: &PgClient) -> Result<(), SqlError> { - Ok(()) - } -} - impl std::ops::Deref for Plant { type Target = PlantArchetype; diff --git a/src/possess/seed.rs b/src/possess/seed.rs index 3b2fcdd..a498df5 100644 --- a/src/possess/seed.rs +++ b/src/possess/seed.rs @@ -3,6 +3,7 @@ use crate::{config, AttributeParseError, Item, CONFIG}; use config::{ArchetypeHandle, ArchetypeKind}; use rusoto_dynamodb::AttributeValue; use serde::{Deserialize, Serialize}; +use sqlx::types::Type as PgType; #[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)] pub struct Seed { @@ -17,10 +18,10 @@ impl Possessable for Seed { PossessionKind::Seed(self) } } -#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, PgType)] pub struct SeedGrower { pub id: String, - pub generations: u64, + pub generations: u32, } impl SeedGrower { pub fn new(id: String, generations: u64) -> Self {