Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add various blob column types with size #850

Merged
merged 1 commit into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
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 @@ -112,7 +112,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