Skip to content

Commit

Permalink
Refactor UUID schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Jul 24, 2021
1 parent 68f369b commit a29e55f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/backend/mysql/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl TableBuilder for MysqlQueryBuilder {
},
ColumnType::Json => "json".into(),
ColumnType::JsonBinary => "json".into(),
ColumnType::Uuid => "binary(16)".into(),
ColumnType::Custom(iden) => iden.to_string(),
ColumnType::Uuid => format!("binary(16)"),
}
)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/backend/postgres/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl TableBuilder for PostgresQueryBuilder {
},
ColumnType::Json => "json".into(),
ColumnType::JsonBinary => "jsonb".into(),
ColumnType::Custom(iden) => iden.to_string(),
ColumnType::Uuid => "uuid".into(),
ColumnType::Custom(iden) => iden.to_string(),
}
)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/backend/sqlite/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ impl TableBuilder for SqliteQueryBuilder {
},
ColumnType::Json => "text".into(),
ColumnType::JsonBinary => "text".into(),
ColumnType::Custom(iden) => iden.to_string(),
ColumnType::Uuid => "text(36)".into(),
ColumnType::Custom(iden) => iden.to_string(),
}
)
.unwrap()
Expand Down
22 changes: 11 additions & 11 deletions src/table/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub enum ColumnType {
Money(Option<(u32, u32)>),
Json,
JsonBinary,
Custom(DynIden),
Uuid,
Custom(DynIden),
}

/// All column specification keywords
Expand Down Expand Up @@ -281,21 +281,27 @@ impl ColumnDef {
}

/// Set column type as json.
/// On MySQL, this is equivalent to json_binary. On MariaDB, this is equivalent to text.
/// On PgSQL, this is equivalent to json.
/// On MySQL, this is equivalent to `json_binary`. On MariaDB, this is equivalent to `text`.
/// On PgSQL, this is equivalent to `json`.
pub fn json(mut self) -> Self {
self.types = Some(ColumnType::Json);
self
}

/// Set column type as json binary.
/// On MySQL, this is equivalent to json. On MariaDB, this is equivalent to text.
/// On PgSQL, this is equivalent to jsonb.
/// On MySQL, this is equivalent to `json`. On MariaDB, this is equivalent to `text`.
/// On PgSQL, this is equivalent to `jsonb`.
pub fn json_binary(mut self) -> Self {
self.types = Some(ColumnType::JsonBinary);
self
}

/// Set column type as uuid
pub fn uuid(mut self) -> Self {
self.types = Some(ColumnType::Uuid);
self
}

/// Use a custom type on this column.
pub fn custom<T: 'static>(mut self, n: T) -> Self
where
Expand All @@ -322,10 +328,4 @@ impl ColumnDef {
pub fn get_column_spec(&self) -> &Vec<ColumnSpec> {
self.spec.as_ref()
}

/// Set column type as uuid
pub fn uuid(mut self) -> Self {
self.types = Some(ColumnType::Uuid);
self
}
}

0 comments on commit a29e55f

Please sign in to comment.