Skip to content

Commit

Permalink
Add various blob column types with size (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 authored Jul 10, 2022
1 parent 1a3e8c4 commit 65017bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 5 additions & 2 deletions sea-orm-codegen/src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{util::escape_rust_keyword, DateTimeCrate};
use heck::{CamelCase, SnakeCase};
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
use sea_query::{ColumnDef, ColumnSpec, ColumnType};
use sea_query::{BlobSize, ColumnDef, ColumnSpec, ColumnType};
use std::fmt::Write as FmtWrite;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -128,7 +128,10 @@ impl Column {
}
ColumnType::Time(_) => quote! { ColumnType::Time.def() },
ColumnType::Date => quote! { ColumnType::Date.def() },
ColumnType::Binary(_) => quote! { ColumnType::Binary.def() },
ColumnType::Binary(BlobSize::Blob(_)) => quote! { ColumnType::Binary.def() },
ColumnType::Binary(BlobSize::Tiny) => quote! { ColumnType::TinyBinary.def() },
ColumnType::Binary(BlobSize::Medium) => quote! { ColumnType::MediumBinary.def() },
ColumnType::Binary(BlobSize::Long) => quote! { ColumnType::LongBinary.def() },
ColumnType::Boolean => quote! { ColumnType::Boolean.def() },
ColumnType::Money(s) => match s {
Some((s1, s2)) => quote! { ColumnType::Money(Some((#s1, #s2))).def() },
Expand Down
14 changes: 13 additions & 1 deletion src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ pub enum ColumnType {
Date,
/// `BINARY` data types contain byte strings—a sequence of octets or bytes.
Binary,
/// Tiny Binary
TinyBinary,
/// Medium Binary
MediumBinary,
/// Long Binary
LongBinary,
/// `BOOLEAN` is the result of a comparison operator
Boolean,
/// `MONEY` data type handles monetary data
Expand Down Expand Up @@ -383,6 +389,9 @@ impl From<ColumnType> for sea_query::ColumnType {
ColumnType::Time => sea_query::ColumnType::Time(None),
ColumnType::Date => sea_query::ColumnType::Date,
ColumnType::Binary => sea_query::ColumnType::Binary(sea_query::BlobSize::Blob(None)),
ColumnType::TinyBinary => sea_query::ColumnType::Binary(sea_query::BlobSize::Tiny),
ColumnType::MediumBinary => sea_query::ColumnType::Binary(sea_query::BlobSize::Medium),
ColumnType::LongBinary => sea_query::ColumnType::Binary(sea_query::BlobSize::Long),
ColumnType::Boolean => sea_query::ColumnType::Boolean,
ColumnType::Money(s) => sea_query::ColumnType::Money(s),
ColumnType::Json => sea_query::ColumnType::Json,
Expand Down Expand Up @@ -419,7 +428,10 @@ impl From<sea_query::ColumnType> for ColumnType {
sea_query::ColumnType::TimestampWithTimeZone(_) => Self::TimestampWithTimeZone,
sea_query::ColumnType::Time(_) => Self::Time,
sea_query::ColumnType::Date => Self::Date,
sea_query::ColumnType::Binary(_) => Self::Binary,
sea_query::ColumnType::Binary(sea_query::BlobSize::Blob(_)) => Self::Binary,
sea_query::ColumnType::Binary(sea_query::BlobSize::Tiny) => Self::TinyBinary,
sea_query::ColumnType::Binary(sea_query::BlobSize::Medium) => Self::MediumBinary,
sea_query::ColumnType::Binary(sea_query::BlobSize::Long) => Self::LongBinary,
sea_query::ColumnType::Boolean => Self::Boolean,
sea_query::ColumnType::Money(s) => Self::Money(s),
sea_query::ColumnType::Json => Self::Json,
Expand Down

0 comments on commit 65017bd

Please sign in to comment.