2020-03-18 02:35:01 +00:00
|
|
|
use sqlx::MySql;
|
2020-03-18 02:26:59 +00:00
|
|
|
use sqlx_test::test_type;
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
// Transparent types are rust-side wrappers over DB types
|
|
|
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
|
|
|
#[sqlx(transparent)]
|
|
|
|
struct Transparent(i32);
|
|
|
|
|
|
|
|
// "Weak" enums map to an integer type indicated by #[repr]
|
|
|
|
#[derive(PartialEq, Copy, Clone, Debug, sqlx::Type)]
|
|
|
|
#[repr(i32)]
|
|
|
|
enum Weak {
|
|
|
|
One = 0,
|
|
|
|
Two = 2,
|
|
|
|
Three = 4,
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Strong" enums can map to TEXT or a custom enum
|
|
|
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
|
|
|
#[sqlx(rename_all = "lowercase")]
|
|
|
|
enum Color {
|
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
Blue,
|
|
|
|
}
|
|
|
|
|
|
|
|
test_type!(transparent(
|
|
|
|
MySql,
|
|
|
|
Transparent,
|
|
|
|
"0" == Transparent(0),
|
|
|
|
"23523" == Transparent(23523)
|
|
|
|
));
|
|
|
|
|
|
|
|
test_type!(weak_enum(
|
|
|
|
MySql,
|
|
|
|
Weak,
|
|
|
|
"0" == Weak::One,
|
|
|
|
"2" == Weak::Two,
|
|
|
|
"4" == Weak::Three
|
|
|
|
));
|
|
|
|
|
2020-03-18 02:35:01 +00:00
|
|
|
test_type!(strong_color_enum(MySql, Color, "'green'" == Color::Green));
|