-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move custom sql types into own file and import it in genera…
…ted schema.rs
- Loading branch information
1 parent
2deb7fc
commit 6824eee
Showing
10 changed files
with
173 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
//https://github.com/diesel-rs/diesel/blob/db6730c9a79135728ec4f87fabdb745d71cb4578/diesel_derives/src/sql_type.rs | ||
use std::sync::atomic::{AtomicU32, Ordering}; | ||
|
||
use diesel::pg::PgTypeMetadata; | ||
|
||
pub static CUSTOM_TYPES: [&(&str, AtomicU32, AtomicU32); 6] = [ | ||
&CARDIO_TYPE, | ||
&DISTANCE_UNIT, | ||
&METCON_TYPE, | ||
&MOVEMENT_DIMENSION, | ||
&POSITION, | ||
&WEEKDAY, | ||
]; | ||
|
||
pub struct CardioType; | ||
|
||
static CARDIO_TYPE: (&str, AtomicU32, AtomicU32) = | ||
("cardio_type", AtomicU32::new(0), AtomicU32::new(0)); | ||
|
||
impl diesel::sql_types::SqlType for CardioType { | ||
type IsNull = diesel::sql_types::is_nullable::NotNull; | ||
} | ||
|
||
impl diesel::sql_types::SingleValue for CardioType {} | ||
|
||
impl diesel::sql_types::HasSqlType<CardioType> for diesel::pg::Pg { | ||
fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata { | ||
PgTypeMetadata::new( | ||
CARDIO_TYPE.1.load(Ordering::Acquire), | ||
CARDIO_TYPE.2.load(Ordering::Acquire), | ||
) | ||
} | ||
} | ||
|
||
pub struct DistanceUnit; | ||
|
||
static DISTANCE_UNIT: (&str, AtomicU32, AtomicU32) = | ||
("distance_unit", AtomicU32::new(0), AtomicU32::new(0)); | ||
|
||
impl diesel::sql_types::SqlType for DistanceUnit { | ||
type IsNull = diesel::sql_types::is_nullable::NotNull; | ||
} | ||
|
||
impl diesel::sql_types::SingleValue for DistanceUnit {} | ||
|
||
impl diesel::sql_types::HasSqlType<DistanceUnit> for diesel::pg::Pg { | ||
fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata { | ||
PgTypeMetadata::new( | ||
DISTANCE_UNIT.1.load(Ordering::Acquire), | ||
DISTANCE_UNIT.2.load(Ordering::Acquire), | ||
) | ||
} | ||
} | ||
|
||
pub struct MetconType; | ||
|
||
static METCON_TYPE: (&str, AtomicU32, AtomicU32) = | ||
("metcon_type", AtomicU32::new(0), AtomicU32::new(0)); | ||
|
||
impl diesel::sql_types::SqlType for MetconType { | ||
type IsNull = diesel::sql_types::is_nullable::NotNull; | ||
} | ||
|
||
impl diesel::sql_types::SingleValue for MetconType {} | ||
|
||
impl diesel::sql_types::HasSqlType<MetconType> for diesel::pg::Pg { | ||
fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata { | ||
PgTypeMetadata::new( | ||
METCON_TYPE.1.load(Ordering::Acquire), | ||
METCON_TYPE.2.load(Ordering::Acquire), | ||
) | ||
} | ||
} | ||
|
||
pub struct MovementDimension; | ||
|
||
static MOVEMENT_DIMENSION: (&str, AtomicU32, AtomicU32) = | ||
("movement_dimension", AtomicU32::new(0), AtomicU32::new(0)); | ||
|
||
impl diesel::sql_types::SqlType for MovementDimension { | ||
type IsNull = diesel::sql_types::is_nullable::NotNull; | ||
} | ||
|
||
impl diesel::sql_types::SingleValue for MovementDimension {} | ||
|
||
impl diesel::sql_types::HasSqlType<MovementDimension> for diesel::pg::Pg { | ||
fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata { | ||
PgTypeMetadata::new( | ||
MOVEMENT_DIMENSION.1.load(Ordering::Acquire), | ||
MOVEMENT_DIMENSION.2.load(Ordering::Acquire), | ||
) | ||
} | ||
} | ||
|
||
pub struct Position; | ||
|
||
static POSITION: (&str, AtomicU32, AtomicU32) = ("position", AtomicU32::new(0), AtomicU32::new(0)); | ||
|
||
impl diesel::sql_types::SqlType for Position { | ||
type IsNull = diesel::sql_types::is_nullable::NotNull; | ||
} | ||
|
||
impl diesel::sql_types::SingleValue for Position {} | ||
|
||
impl diesel::sql_types::HasSqlType<Position> for diesel::pg::Pg { | ||
fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata { | ||
PgTypeMetadata::new( | ||
POSITION.1.load(Ordering::Acquire), | ||
POSITION.2.load(Ordering::Acquire), | ||
) | ||
} | ||
} | ||
|
||
pub struct Weekday; | ||
|
||
static WEEKDAY: (&str, AtomicU32, AtomicU32) = ("weekday", AtomicU32::new(0), AtomicU32::new(0)); | ||
|
||
impl diesel::sql_types::SqlType for Weekday { | ||
type IsNull = diesel::sql_types::is_nullable::NotNull; | ||
} | ||
|
||
impl diesel::sql_types::SingleValue for Weekday {} | ||
|
||
impl diesel::sql_types::HasSqlType<Weekday> for diesel::pg::Pg { | ||
fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata { | ||
PgTypeMetadata::new( | ||
WEEKDAY.1.load(Ordering::Acquire), | ||
WEEKDAY.2.load(Ordering::Acquire), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#[cfg(feature = "db")] | ||
pub mod custom_sql_types; | ||
#[cfg(feature = "db")] | ||
pub mod schema; | ||
mod types; | ||
pub use types::*; |
Oops, something went wrong.