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

Bump version of sqlx, sea-query, sea-schema, time and uuid #834

Merged
merged 9 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ path = "src/lib.rs"
async-stream = { version = "^0.3" }
async-trait = { version = "^0.1" }
chrono = { version = "^0", optional = true }
time = { version = "^0.2", optional = true }
time = { version = "^0.3", optional = true }
futures = { version = "^0.3" }
futures-util = { version = "^0.3" }
log = { version = "^0" }
tracing = { version = "0.1", features = ["log"] }
rust_decimal = { version = "^1", optional = true }
sea-orm-macros = { version = "^0.8.0", path = "sea-orm-macros", optional = true }
sea-query = { version = "^0.24.5", features = ["thread-safe"] }
sea-query = { version = "^0.26.0", features = ["thread-safe"] }
ikrivosheev marked this conversation as resolved.
Show resolved Hide resolved
sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1", optional = true }
sqlx = { version = "^0.5", optional = true }
uuid = { version = "0.8", features = ["serde", "v4"], optional = true }
sqlx = { version = "^0.6", optional = true }
uuid = { version = "^1", features = ["serde", "v4"], optional = true }
ouroboros = "0.15"
url = "^2.2"
once_cell = "1.8"
Expand All @@ -53,6 +53,7 @@ rust_decimal_macros = { version = "^1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
sea-orm = { path = ".", features = ["mock", "debug-print"] }
pretty_assertions = { version = "^0.7" }
time = { version = "^0.3", features = ["macros"] }
billy1624 marked this conversation as resolved.
Show resolved Hide resolved

[features]
debug-print = []
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ clap = { version = "^3.2", features = ["env", "derive"] }
dotenv = { version = "^0.15" }
async-std = { version = "^1.9", features = [ "attributes", "tokio1" ] }
sea-orm-codegen = { version = "^0.8.0", path = "../sea-orm-codegen", optional = true }
sea-schema = { version = "^0.8.1" }
sqlx = { version = "^0.5", default-features = false, features = [ "mysql", "postgres" ], optional = true }
sea-schema = { version = "^0.9.2" }
sqlx = { version = "^0.6", default-features = false, features = [ "mysql", "postgres" ], optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing = { version = "0.1" }
url = "^2.2"
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "sea_orm_codegen"
path = "src/lib.rs"

[dependencies]
sea-query = { version = "^0.24.0" }
sea-query = { version = "^0.26.0" }
syn = { version = "^1", default-features = false, features = [
"derive",
"parsing",
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-codegen/src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mod tests {
use crate::Column;
use proc_macro2::TokenStream;
use quote::quote;
use sea_query::{Alias, ColumnDef, ColumnType, SeaRc};
use sea_query::{Alias, BlobSize, ColumnDef, ColumnType, SeaRc};

fn setup() -> Vec<Column> {
macro_rules! make_col {
Expand Down Expand Up @@ -243,7 +243,7 @@ mod tests {
make_col!("CakeFillingId", ColumnType::BigUnsigned(Some(12))),
make_col!("cake-filling-id", ColumnType::Float(None)),
make_col!("CAKE_FILLING_ID", ColumnType::Double(None)),
make_col!("CAKE-FILLING-ID", ColumnType::Binary(None)),
make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Blob(None))),
make_col!("CAKE", ColumnType::Boolean),
make_col!("date", ColumnType::Date),
make_col!("time", ColumnType::Time(None)),
Expand Down
5 changes: 2 additions & 3 deletions sea-orm-macros/src/derives/try_getable_from_json.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote, quote_spanned};
use syn::{ext::IdentExt, Data, DataStruct, Field, Fields};
use quote::quote;

pub fn expand_derive_from_json_query_result(ident: Ident, data: Data) -> syn::Result<TokenStream> {
pub fn expand_derive_from_json_query_result(ident: Ident) -> syn::Result<TokenStream> {
Ok(quote!(
#[automatically_derived]
impl sea_orm::TryGetableFromJson for #ident {}
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@ pub fn derive_migration_name(input: TokenStream) -> TokenStream {

#[proc_macro_derive(FromJsonQueryResult)]
pub fn derive_from_json_query_result(input: TokenStream) -> TokenStream {
let DeriveInput { ident, data, .. } = parse_macro_input!(input);
let DeriveInput { ident, .. } = parse_macro_input!(input);

match derives::expand_derive_from_json_query_result(ident, data) {
match derives::expand_derive_from_json_query_result(ident) {
Ok(ts) => ts.into(),
Err(e) => e.to_compile_error().into(),
}
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ clap = { version = "^3.2", features = ["env", "derive"] }
dotenv = { version = "^0.15" }
sea-orm = { version = "^0.8.0", path = "../", default-features = false, features = ["macros"] }
sea-orm-cli = { version = "^0.8.1", path = "../sea-orm-cli", default-features = false }
sea-schema = { version = "^0.8.1" }
sea-schema = { version = "^0.9.2" }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

Expand Down
2 changes: 1 addition & 1 deletion src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl ConnectOptions {
opt = opt.min_connections(min_connections);
}
if let Some(connect_timeout) = self.connect_timeout {
opt = opt.connect_timeout(connect_timeout);
opt = opt.acquire_timeout(connect_timeout);
}
if let Some(idle_timeout) = self.idle_timeout {
opt = opt.idle_timeout(Some(idle_timeout));
Expand Down
2 changes: 1 addition & 1 deletion src/database/stream/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> Drop for MetricStream<'a> {
fn drop(&mut self) {
if let (Some(callback), Some(elapsed)) = (self.metric_callback.as_deref(), self.elapsed) {
let info = crate::metric::Info {
elapsed: elapsed,
elapsed,
statement: self.stmt,
failed: false,
};
Expand Down
8 changes: 4 additions & 4 deletions src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr {
/// ```
fn starts_with(&self, s: &str) -> SimpleExpr {
let pattern = format!("{}%", s);
Expr::tbl(self.entity_name(), *self).like(&pattern)
Expr::tbl(self.entity_name(), *self).like(pattern)
}

/// ```
Expand All @@ -260,7 +260,7 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr {
/// ```
fn ends_with(&self, s: &str) -> SimpleExpr {
let pattern = format!("%{}", s);
Expr::tbl(self.entity_name(), *self).like(&pattern)
Expr::tbl(self.entity_name(), *self).like(pattern)
}

/// ```
Expand All @@ -276,7 +276,7 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr {
/// ```
fn contains(&self, s: &str) -> SimpleExpr {
let pattern = format!("%{}%", s);
Expr::tbl(self.entity_name(), *self).like(&pattern)
Expr::tbl(self.entity_name(), *self).like(pattern)
}

bind_func_no_params!(max);
Expand Down Expand Up @@ -382,7 +382,7 @@ impl From<ColumnType> for sea_query::ColumnType {
ColumnType::TimestampWithTimeZone => sea_query::ColumnType::TimestampWithTimeZone(None),
ColumnType::Time => sea_query::ColumnType::Time(None),
ColumnType::Date => sea_query::ColumnType::Date,
ColumnType::Binary => sea_query::ColumnType::Binary(None),
ColumnType::Binary => sea_query::ColumnType::Binary(sea_query::BlobSize::Blob(None)),
ColumnType::Boolean => sea_query::ColumnType::Boolean,
ColumnType::Money(s) => sea_query::ColumnType::Money(s),
ColumnType::Json => sea_query::ColumnType::Json,
Expand Down
23 changes: 11 additions & 12 deletions src/executor/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ where
// so that self is dropped before entering await
let mut query = self.query;
if db.support_returning() && <A::Entity as EntityTrait>::PrimaryKey::iter().count() > 0 {
let mut returning = Query::select();
returning.columns(
let returning = Query::returning().columns(
<A::Entity as EntityTrait>::PrimaryKey::iter().map(|c| c.into_column_ref()),
);
query.returning(returning);
Expand Down Expand Up @@ -149,16 +148,16 @@ where
let db_backend = db.get_database_backend();
let found = match db.support_returning() {
true => {
let mut returning = Query::select();
returning.exprs(<A::Entity as EntityTrait>::Column::iter().map(|c| {
let col = Expr::col(c);
let col_def = ColumnTrait::def(&c);
let col_type = col_def.get_column_type();
match col_type.get_enum_name() {
Some(_) => col.as_enum(Alias::new("text")),
None => col.into(),
}
}));
let returning =
Query::returning().exprs(<A::Entity as EntityTrait>::Column::iter().map(|c| {
let col = Expr::col(c);
let col_def = ColumnTrait::def(&c);
let col_type = col_def.get_column_type();
match col_type.get_enum_name() {
Some(_) => col.as_enum(Alias::new("text")),
None => col.into(),
}
}));
insert_statement.returning(returning);
SelectorRaw::<SelectModel<<A::Entity as EntityTrait>::Model>>::from_statement(
db_backend.build(&insert_statement),
Expand Down
5 changes: 4 additions & 1 deletion src/executor/paginator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ where
let number_of_items = self.num_items().await?;
let number_of_pages = self.compute_pages_number(number_of_items);

Ok(ItemsAndPagesNumber { number_of_items, number_of_pages })
Ok(ItemsAndPagesNumber {
number_of_items,
number_of_pages,
})
}

/// Compute the number of pages for the current page
Expand Down
42 changes: 41 additions & 1 deletion src/executor/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ try_getable_all!(i32);
try_getable_all!(i64);
try_getable_unsigned!(u8);
try_getable_unsigned!(u16);
try_getable_all!(u32);
try_getable_mysql!(u64);
try_getable_all!(f32);
try_getable_all!(f64);
Expand Down Expand Up @@ -391,6 +390,47 @@ impl TryGetable for Decimal {
#[cfg(feature = "with-uuid")]
try_getable_all!(uuid::Uuid);

impl TryGetable for u32 {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
let _column = format!("{}{}", pre, col);
match &res.row {
#[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => {
use sqlx::Row;
row.try_get::<Option<u32>, _>(_column.as_str())
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
.and_then(|opt| opt.ok_or(TryGetError::Null))
}
#[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => {
use sqlx::postgres::types::Oid;
// Since 0.6.0, SQLx has dropped direct mapping from PostgreSQL's OID to Rust's `u32`;
// Instead, `u32` was wrapped by a `sqlx::Oid`.
use sqlx::Row;
row.try_get::<Option<Oid>, _>(_column.as_str())
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
.and_then(|opt| opt.ok_or(TryGetError::Null))
.map(|oid| oid.0)
}
#[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(row) => {
use sqlx::Row;
row.try_get::<Option<u32>, _>(_column.as_str())
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
.and_then(|opt| opt.ok_or(TryGetError::Null))
}
#[cfg(feature = "mock")]
#[allow(unused_variables)]
QueryResultRow::Mock(row) => row.try_get(_column.as_str()).map_err(|e| {
debug_print!("{:#?}", e.to_string());
TryGetError::Null
}),
#[allow(unreachable_patterns)]
_ => unreachable!(),
}
}
}

// TryGetableMany //

/// Perform a query on multiple columns
Expand Down
20 changes: 10 additions & 10 deletions src/executor/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ where
{
match db.support_returning() {
true => {
let mut returning = Query::select();
returning.exprs(<A::Entity as EntityTrait>::Column::iter().map(|c| {
let col = Expr::col(c);
let col_def = c.def();
let col_type = col_def.get_column_type();
match col_type.get_enum_name() {
Some(_) => col.as_enum(Alias::new("text")),
None => col.into(),
}
}));
let returning =
Query::returning().exprs(<A::Entity as EntityTrait>::Column::iter().map(|c| {
let col = Expr::col(c);
let col_def = c.def();
let col_type = col_def.get_column_type();
match col_type.get_enum_name() {
Some(_) => col.as_enum(Alias::new("text")),
None => col.into(),
}
}));
query.returning(returning);
let db_backend = db.get_database_backend();
let found: Option<<A::Entity as EntityTrait>::Model> =
Expand Down
3 changes: 2 additions & 1 deletion src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ pub(crate) fn unpack_table_ref(table_ref: &TableRef) -> DynIden {
| TableRef::TableAlias(tbl, _)
| TableRef::SchemaTableAlias(_, tbl, _)
| TableRef::DatabaseSchemaTableAlias(_, _, tbl, _)
| TableRef::SubQuery(_, tbl) => SeaRc::clone(tbl),
| TableRef::SubQuery(_, tbl)
| TableRef::ValuesList(_, tbl) => SeaRc::clone(tbl),
}
}
8 changes: 6 additions & 2 deletions src/query/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl FromQueryResult for JsonValue {
#[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => {
use serde_json::json;
use sqlx::{Column, Postgres, Row, Type};
use sqlx::{postgres::types::Oid, Column, Postgres, Row, Type};
for column in row.columns() {
let col = if !column.name().starts_with(pre) {
continue;
Expand All @@ -89,7 +89,11 @@ impl FromQueryResult for JsonValue {
match_postgres_type!(i64);
// match_postgres_type!(u8); // unsupported by SQLx Postgres
// match_postgres_type!(u16); // unsupported by SQLx Postgres
match_postgres_type!(u32);
// Since 0.6.0, SQLx has dropped direct mapping from PostgreSQL's OID to Rust's `u32`;
// Instead, `u32` was wrapped by a `sqlx::Oid`.
if <Oid as Type<Postgres>>::type_info().eq(col_type) {
try_get_type!(u32, col)
}
// match_postgres_type!(u64); // unsupported by SQLx Postgres
match_postgres_type!(f32);
match_postgres_type!(f64);
Expand Down
2 changes: 1 addition & 1 deletion tests/common/features/json_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct StringVec(pub Vec<String>);

impl From<StringVec> for Value {
fn from(source: StringVec) -> Self {
Value::String(serde_json::to_string(&source).ok().map(|s| Box::new(s)))
Value::String(serde_json::to_string(&source).ok().map(Box::new))
}
}

Expand Down
11 changes: 4 additions & 7 deletions tests/json_struct_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ pub async fn insert_json_struct_1(db: &DatabaseConnection) -> Result<(), DbErr>
name: "apple".into(),
price: 12.01,
notes: Some("hand picked, organic".into()),
}
.into(),
},
json_value_opt: Some(KeyValue {
id: 1,
name: "apple".into(),
price: 12.01,
notes: Some("hand picked, organic".into()),
})
.into(),
}),
};

let result = model.clone().into_active_model().insert(db).await?;
Expand Down Expand Up @@ -79,9 +77,8 @@ pub async fn insert_json_struct_2(db: &DatabaseConnection) -> Result<(), DbErr>
name: "orange".into(),
price: 10.93,
notes: None,
}
.into(),
json_value_opt: None.into(),
},
json_value_opt: None,
};

let result = model.clone().into_active_model().insert(db).await?;
Expand Down
4 changes: 2 additions & 2 deletions tests/returning_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ async fn main() -> Result<(), DbErr> {
])
.and_where(Column::Id.eq(1));

let mut returning = Query::select();
returning.columns(vec![Column::Id, Column::Name, Column::ProfitMargin]);
let returning =
Query::returning().columns(vec![Column::Id, Column::Name, Column::ProfitMargin]);

create_tables(db).await?;

Expand Down
2 changes: 1 addition & 1 deletion tests/time_crate_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use sea_orm::{entity::prelude::*, DatabaseConnection, IntoActiveModel};
use time::{date, time};
use time::macros::{date, time};

#[sea_orm_macros::test]
#[cfg(any(
Expand Down