Skip to content

Commit

Permalink
encode PokemonType as json for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
meuter committed Apr 1, 2024
1 parent 0bc913e commit 04ec4ce
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions examples/pokemon/main.rs
@@ -1,7 +1,9 @@
use miniorm::{Create, Entity, Store};
use serde::{Deserialize, Serialize};
use sqlx::{prelude::Type, FromRow, MySql};
use std::string::ToString;

#[derive(Debug, Clone, Eq, PartialEq, Type)]
#[derive(Debug, Clone, Eq, PartialEq, Type, Serialize, Deserialize)]
pub enum PokemonType {
Unknown,
Fire,
Expand All @@ -12,21 +14,13 @@ pub enum PokemonType {
Rock,
}

impl Default for PokemonType {
fn default() -> Self {
Self::Unknown
}
}

/// A todo including a `description` and a `done` flag
#[derive(Debug, Clone, Eq, PartialEq, FromRow, Entity)]
struct Pokemon {
#[mysql(TEXT NOT NULL)]
name: String,

#[mysql(VARCHAR(40) NOT NULL)]
// TODO: figure out the ENUM type in mysql
#[sqlx(skip)]
#[sqlx(json)]
ty: PokemonType,
}

Expand All @@ -41,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let pikatchu = Pokemon {
name: "Pikatchu".to_string(),
ty: PokemonType::default(),
ty: PokemonType::Electric,
};

println!("Recreating table...");
Expand Down

0 comments on commit 04ec4ce

Please sign in to comment.