Skip to content

Commit

Permalink
Bump SeaQuery and update blob data types
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jan 30, 2024
1 parent c69430c commit 8003968
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ path = "src/lib.rs"
[dependencies]
futures = { version = "0.3", default-features = false, optional = true, features = ["alloc"] }
sea-schema-derive = { version = "0.2.0", path = "sea-schema-derive", default-features = false }
sea-query = { version = "0.30.0", git = "https://github.com/seaql/sea-query", branch = "sqlite-types", default-features = false, features = ["derive"] }
sea-query-binder = { version = "0.5.0", git = "https://github.com/seaql/sea-query", branch = "sqlite-types", default-features = false, optional = true }
sea-query = { version = "0.31.0", git = "https://github.com/seaql/sea-query", branch = "data-type-blob", default-features = false, features = ["derive"] }
sea-query-binder = { version = "0.5.0", git = "https://github.com/seaql/sea-query", branch = "data-type-blob", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive"] }
sqlx = { version = "0.7", default-features = false, optional = true }
log = { version = "0.4", default-features = false, optional = true }
Expand Down
20 changes: 10 additions & 10 deletions src/mysql/writer/column.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::mysql::def::{CharSet, ColumnDefault, ColumnInfo, NumericAttr, StringAttr, Type};
use sea_query::{
Alias, BlobSize, ColumnDef, DynIden, EscapeBuilder, Expr, Iden, IntoIden, Keyword,
MysqlQueryBuilder, SimpleExpr,
extension::mysql::MySqlType, Alias, ColumnDef, DynIden, EscapeBuilder, Expr, Iden, IntoIden,
Keyword, MysqlQueryBuilder, SimpleExpr,
};
use std::fmt::Write;

Expand Down Expand Up @@ -155,15 +155,15 @@ impl ColumnInfo {
}
Type::Binary(str_attr) => {
match str_attr.length {
Some(length) => col_def.binary_len(length),
_ => col_def.binary(),
Some(length) => col_def.binary(length),
None => col_def.custom(MySqlType::Blob),
};
col_def = self.write_str_attr(col_def, str_attr);
}
Type::Varbinary(str_attr) => {
match str_attr.length {
Some(length) => col_def.var_binary(length),
None => col_def.binary(),
None => col_def.custom(MySqlType::Blob),
};
}
Type::Text(str_attr) => {
Expand All @@ -184,18 +184,18 @@ impl ColumnInfo {
}
Type::Blob(blob_attr) => {
match blob_attr.length {
Some(length) => col_def.binary_len(length),
None => col_def.binary(),
Some(length) => col_def.binary(length),
None => col_def.custom(MySqlType::Blob),
};
}
Type::TinyBlob => {
col_def.blob(BlobSize::Tiny);
col_def.custom(MySqlType::TinyBlob);
}
Type::MediumBlob => {
col_def.blob(BlobSize::Medium);
col_def.custom(MySqlType::MediumBlob);
}
Type::LongBlob => {
col_def.blob(BlobSize::Long);
col_def.custom(MySqlType::LongBlob);
}
Type::Enum(enum_attr) => {
let name = Alias::new(&self.name);
Expand Down
11 changes: 6 additions & 5 deletions src/postgres/writer/column.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::postgres::def::{ColumnInfo, Type};
use sea_query::{Alias, BlobSize, ColumnDef, ColumnType, DynIden, IntoIden, PgInterval, RcOrArc};
use sea_query::{Alias, ColumnDef, ColumnType, DynIden, IntoIden, PgInterval, RcOrArc, StringLen};
use std::{convert::TryFrom, fmt::Write};

impl ColumnInfo {
Expand Down Expand Up @@ -72,12 +72,13 @@ impl ColumnInfo {
Type::Serial => ColumnType::Integer,
Type::BigSerial => ColumnType::BigInteger,
Type::Money => ColumnType::Money(None),
Type::Varchar(string_attr) => {
ColumnType::String(string_attr.length.map(Into::into))
}
Type::Varchar(string_attr) => match string_attr.length {
Some(length) => ColumnType::String(StringLen::N(length.into())),
None => ColumnType::String(StringLen::None),
},
Type::Char(string_attr) => ColumnType::Char(string_attr.length.map(Into::into)),
Type::Text => ColumnType::Text,
Type::Bytea => ColumnType::Binary(BlobSize::Blob(None)),
Type::Bytea => ColumnType::VarBinary(StringLen::None),
// The SQL standard requires that writing just timestamp be equivalent to timestamp without time zone,
// and PostgreSQL honors that behavior. (https://www.postgresql.org/docs/current/datatype-datetime.html)
Type::Timestamp(_) => ColumnType::DateTime,
Expand Down
7 changes: 4 additions & 3 deletions src/sqlite/def/column.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{parse_type, DefaultType, Type};
use super::{parse_type, DefaultType};
use sea_query::{
foreign_key::ForeignKeyAction as SeaQueryForeignKeyAction, Alias, Index, IndexCreateStatement,
foreign_key::ForeignKeyAction as SeaQueryForeignKeyAction, Alias, ColumnType, Index,
IndexCreateStatement,
};
use std::num::ParseIntError;

Expand All @@ -12,7 +13,7 @@ use crate::sqlx_types::{sqlite::SqliteRow, Row};
pub struct ColumnInfo {
pub cid: i32,
pub name: String,
pub r#type: Type,
pub r#type: ColumnType,
pub not_null: bool,
pub default_value: DefaultType,
pub primary_key: bool,
Expand Down
21 changes: 12 additions & 9 deletions src/sqlite/def/types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use sea_query::{BlobSize, ColumnType};
use sea_query::{ColumnType, StringLen};
use std::num::ParseIntError;

pub type Type = ColumnType;

pub fn parse_type(data_type: &str) -> Result<ColumnType, ParseIntError> {
let mut type_name = data_type;
let mut parts: Vec<u32> = Vec::new();
Expand All @@ -20,7 +18,10 @@ pub fn parse_type(data_type: &str) -> Result<ColumnType, ParseIntError> {
}
Ok(match type_name.to_lowercase().as_str() {
"char" => ColumnType::Char(parts.into_iter().next()),
"varchar" => ColumnType::String(parts.into_iter().next()),
"varchar" => ColumnType::String(match parts.into_iter().next() {
Some(length) => StringLen::N(length),
None => StringLen::None,
}),
"text" => ColumnType::Text,
"tinyint" => ColumnType::TinyInteger,
"smallint" => ColumnType::SmallInteger,
Expand All @@ -38,11 +39,13 @@ pub fn parse_type(data_type: &str) -> Result<ColumnType, ParseIntError> {
"timestamp_with_timezone_text" => ColumnType::TimestampWithTimeZone,
"time_text" => ColumnType::Time,
"date_text" => ColumnType::Date,
"tinyblob" => ColumnType::Binary(BlobSize::Tiny),
"mediumblob" => ColumnType::Binary(BlobSize::Medium),
"longblob" => ColumnType::Binary(BlobSize::Long),
"blob" => ColumnType::Binary(BlobSize::Blob(parts.into_iter().next())),
"varbinary_blob" if parts.len() == 1 => ColumnType::VarBinary(parts[0]),
"blob" if parts.len() == 1 => ColumnType::Binary(parts[0]),
"varbinary_blob" if parts.len() == 1 => {
ColumnType::VarBinary(match parts.into_iter().next() {
Some(length) => StringLen::N(length),
None => StringLen::None,
})
}
"boolean" => ColumnType::Boolean,
"money" => ColumnType::Money(if parts.len() == 2 {
Some((parts[0], parts[1]))
Expand Down

0 comments on commit 8003968

Please sign in to comment.