Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ seaography = ["sea-orm-macros/seaography"]
# This allows us to develop using a local version of sea-query
# [patch.crates-io]
# sea-query = { path = "../sea-query" }
[patch.crates-io]
sea-query = { git = "https://github.com/Huliiiiii/sea-query.git", branch = "expr-2" }
4 changes: 2 additions & 2 deletions sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res

if let Some(select_as) = select_as {
columns_select_as.push(quote! {
Self::#field_name => expr.cast_as(#select_as)
Self::#field_name => ::sea_query::ExprTrait::cast_as(expr, #select_as)
});
}
if let Some(save_as) = save_as {
columns_save_as.push(quote! {
Self::#field_name => val.cast_as(#save_as)
Self::#field_name => ::sea_query::ExprTrait::cast_as(val, #save_as)
});
}

Expand Down
3 changes: 2 additions & 1 deletion sea-orm-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ pub fn derive_from_json_query_result(input: TokenStream) -> TokenStream {
///
/// ```rust
/// use sea_orm::{entity::prelude::*, DerivePartialModel, FromQueryResult};
/// use sea_orm::sea_query::ExprTrait;
///
/// #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
/// #[sea_orm(table_name = "posts")]
Expand Down Expand Up @@ -777,7 +778,7 @@ pub fn derive_from_json_query_result(input: TokenStream) -> TokenStream {
///
/// If all fields in the partial model is `from_expr`, the specifying the `entity` can be skipped.
/// ```
/// use sea_orm::{entity::prelude::*, sea_query::Expr, DerivePartialModel, FromQueryResult};
/// use sea_orm::{entity::prelude::*, sea_query::{Expr, ExprTrait}, DerivePartialModel, FromQueryResult};
///
/// #[derive(Debug, FromQueryResult, DerivePartialModel)]
/// struct SelectResult {
Expand Down
2 changes: 1 addition & 1 deletion src/entity/active_enum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{ColIdx, ColumnDef, DbErr, Iterable, QueryResult, TryFromU64, TryGetError, TryGetable};
use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType};
use sea_query::{DynIden, Expr, ExprTrait, Nullable, SimpleExpr, Value, ValueType};

/// A Rust representation of enum defined in database.
///
Expand Down
13 changes: 9 additions & 4 deletions src/entity/column.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{DbBackend, EntityName, Iden, IdenStatic, IntoSimpleExpr, Iterable};
use sea_query::{
Alias, BinOper, DynIden, Expr, IntoIden, IntoLikeExpr, SeaRc, SelectStatement, SimpleExpr,
Value,
Alias, BinOper, DynIden, Expr, ExprTrait, IntoIden, IntoLikeExpr, SeaRc, SelectStatement,
SimpleExpr, Value,
};
use std::str::FromStr;

Expand Down Expand Up @@ -460,7 +460,6 @@ where
*boxed
}

let expr = expr.into();
match expr {
SimpleExpr::Value(Value::Array(ArrayType::Json, Some(json_vec))) => {
// flatten Array(Vec<Json>) into Json
Expand All @@ -481,7 +480,7 @@ where
}
_ => match col_type.get_enum_name() {
Some(enum_name) => f(expr, SeaRc::clone(enum_name), col_type),
None => expr.into(),
None => expr,
},
}
}
Expand Down Expand Up @@ -1027,6 +1026,8 @@ mod tests {
use crate::{ActiveModelTrait, ActiveValue, Update};

mod hello_expanded {
use sea_query::ExprTrait;

use crate as sea_orm;
use crate::entity::prelude::*;
use crate::sea_query::{Expr, SimpleExpr};
Expand Down Expand Up @@ -1158,6 +1159,8 @@ mod tests {
use crate::{ActiveModelTrait, ActiveValue, Update};

mod hello_expanded {
use sea_query::ExprTrait;

use crate as sea_orm;
use crate::entity::prelude::*;
use crate::sea_query::{Expr, SimpleExpr};
Expand Down Expand Up @@ -1289,6 +1292,8 @@ mod tests {
use crate::{ActiveModelTrait, ActiveValue, Update};

mod hello_expanded {
use sea_query::ExprTrait;

use crate as sea_orm;
use crate::entity::prelude::*;
use crate::sea_query::{Expr, SimpleExpr};
Expand Down
4 changes: 2 additions & 2 deletions src/entity/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl RelationDef {
///
/// ```
/// use sea_orm::{entity::*, query::*, DbBackend, tests_cfg::{cake, cake_filling}};
/// use sea_query::{Expr, IntoCondition};
/// use sea_query::{Expr, ExprTrait, IntoCondition};
///
/// assert_eq!(
/// cake::Entity::find()
Expand Down Expand Up @@ -328,7 +328,7 @@ impl RelationDef {
///
/// ```
/// use sea_orm::{entity::*, query::*, DbBackend, tests_cfg::{cake, cake_filling}};
/// use sea_query::{Expr, IntoCondition, ConditionType};
/// use sea_query::{Expr, ExprTrait, IntoCondition, ConditionType};
///
/// assert_eq!(
/// cake::Entity::find()
Expand Down
4 changes: 2 additions & 2 deletions src/executor/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
SelectThree, SelectThreeModel, SelectTwo, SelectTwoModel, SelectorTrait,
};
use sea_query::{
Condition, DynIden, Expr, IntoValueTuple, Order, SeaRc, SelectStatement, SimpleExpr, Value,
ValueTuple,
Condition, DynIden, Expr, ExprTrait, IntoValueTuple, Order, SeaRc, SelectStatement, SimpleExpr,
Value, ValueTuple,
};
use std::marker::PhantomData;
use strum::IntoEnumIterator as Iterable;
Expand Down
12 changes: 6 additions & 6 deletions src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{
ModelTrait, PrimaryKeyToColumn, RelationDef,
};
use sea_query::{
Alias, Expr, Iden, IntoCondition, IntoIden, LockBehavior, LockType, NullOrdering, SeaRc,
SelectExpr, SelectStatement, SimpleExpr, TableRef,
Alias, Expr, ExprTrait, Iden, IntoCondition, IntoIden, LockBehavior, LockType, NullOrdering,
SeaRc, SelectExpr, SelectStatement, SimpleExpr, TableRef,
};
pub use sea_query::{Condition, ConditionalStatement, DynIden, JoinType, Order, OrderedStatement};

Expand Down Expand Up @@ -284,7 +284,7 @@ pub trait QuerySelect: Sized {

/// Add an AND HAVING expression
/// ```
/// use sea_orm::{sea_query::{Alias, Expr}, entity::*, query::*, tests_cfg::cake, DbBackend};
/// use sea_orm::{sea_query::{Alias, Expr, ExprTrait}, entity::*, query::*, tests_cfg::cake, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
Expand Down Expand Up @@ -731,7 +731,7 @@ pub trait QueryFilter: Sized {
/// Like above, but using the `ANY` operator. Postgres only.
///
/// ```
/// use sea_orm::sea_query::{extension::postgres::PgFunc, Expr};
/// use sea_orm::sea_query::{extension::postgres::PgFunc, Expr, ExprTrait};
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
///
/// assert_eq!(
Expand Down Expand Up @@ -790,7 +790,7 @@ pub trait QueryFilter: Sized {
///
/// A slightly more complex example.
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::Expr, DbBackend};
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::{Expr, ExprTrait}, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
Expand All @@ -815,7 +815,7 @@ pub trait QueryFilter: Sized {
/// ```
/// Use a sea_query expression
/// ```
/// use sea_orm::{entity::*, query::*, sea_query::Expr, tests_cfg::fruit, DbBackend};
/// use sea_orm::{entity::*, query::*, sea_query::{Expr, ExprTrait}, tests_cfg::fruit, DbBackend};
///
/// assert_eq!(
/// fruit::Entity::find()
Expand Down
2 changes: 1 addition & 1 deletion src/query/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod tests {
RelationTrait,
};
use pretty_assertions::assert_eq;
use sea_query::{Alias, ConditionType, Expr, IntoCondition, JoinType};
use sea_query::{Alias, ConditionType, Expr, ExprTrait, IntoCondition, JoinType};

#[test]
fn join_1() {
Expand Down
4 changes: 3 additions & 1 deletion src/query/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use crate::{
Related, RelationType, Select,
};
use async_trait::async_trait;
use sea_query::{ColumnRef, DynIden, Expr, IntoColumnRef, SimpleExpr, TableRef, ValueTuple};
use sea_query::{
ColumnRef, DynIden, Expr, ExprTrait, IntoColumnRef, SimpleExpr, TableRef, ValueTuple,
};
use std::{
collections::{HashMap, HashSet},
str::FromStr,
Expand Down
12 changes: 0 additions & 12 deletions src/query/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ where
}
}

impl ColumnAsExpr for Expr {
fn into_column_as_expr(self) -> SimpleExpr {
self.into_simple_expr()
}
}

impl ColumnAsExpr for SimpleExpr {
fn into_column_as_expr(self) -> SimpleExpr {
self.into_simple_expr()
Expand All @@ -146,12 +140,6 @@ where
}
}

impl IntoSimpleExpr for Expr {
fn into_simple_expr(self) -> SimpleExpr {
self.into()
}
}

impl IntoSimpleExpr for SimpleExpr {
fn into_simple_expr(self) -> SimpleExpr {
self
Expand Down
2 changes: 1 addition & 1 deletion src/tests_cfg/entity_linked.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::entity::prelude::*;
use sea_query::{Expr, IntoCondition};
use sea_query::{Expr, ExprTrait, IntoCondition};

#[derive(Debug)]
pub struct CakeToFilling;
Expand Down
17 changes: 9 additions & 8 deletions tests/active_enum_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use sea_orm::{
sea_query::{BinOper, Expr},
ActiveEnum as ActiveEnumTrait, DatabaseConnection, FromQueryResult, QuerySelect,
};
use sea_query::ExprTrait;

#[sea_orm_macros::test]
async fn main() -> Result<(), DbErr> {
Expand Down Expand Up @@ -141,10 +142,10 @@ pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> {
assert_eq!(
model,
Entity::find()
.filter(
Expr::col(Column::Tea)
.binary(BinOper::In, Expr::tuple([Tea::EverydayTea.as_enum()]))
)
.filter(Expr::col(Column::Tea).binary(
BinOper::In,
Expr::tuple([ActiveEnumTrait::as_enum(&Tea::EverydayTea)])
))
.one(db)
.await?
.unwrap()
Expand Down Expand Up @@ -173,10 +174,10 @@ pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> {
model,
Entity::find()
.filter(Column::Tea.is_not_null())
.filter(
Expr::col(Column::Tea)
.binary(BinOper::NotIn, Expr::tuple([Tea::BreakfastTea.as_enum()]))
)
.filter(Expr::col(Column::Tea).binary(
BinOper::NotIn,
Expr::tuple([ActiveEnumTrait::as_enum(&Tea::BreakfastTea)])
))
.one(db)
.await?
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions tests/cursor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod common;
pub use common::{features::*, setup::*, TestContext};
use pretty_assertions::assert_eq;
use sea_orm::{entity::prelude::*, DerivePartialModel, FromQueryResult, QuerySelect, Set};
use sea_query::ExprTrait;
use serde_json::json;

#[sea_orm_macros::test]
Expand Down
2 changes: 1 addition & 1 deletion tests/dyn_table_name_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use sea_orm::{
entity::prelude::*, DatabaseConnection, Delete, IntoActiveModel, Iterable, QueryTrait, Set,
Update,
};
use sea_query::{Expr, Query};
use sea_query::{Expr, ExprTrait, Query};

#[sea_orm_macros::test]
async fn main() -> Result<(), DbErr> {
Expand Down
9 changes: 5 additions & 4 deletions tests/enum_primary_key_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use sea_orm::{
sea_query::{BinOper, Expr},
ActiveEnum as ActiveEnumTrait, DatabaseConnection,
};
use sea_query::ExprTrait;

#[sea_orm_macros::test]
async fn main() -> Result<(), DbErr> {
Expand Down Expand Up @@ -102,10 +103,10 @@ pub async fn insert_teas(db: &DatabaseConnection) -> Result<(), DbErr> {
assert_eq!(
model,
Entity::find()
.filter(
Expr::col(Column::Id)
.binary(BinOper::In, Expr::tuple([Tea::EverydayTea.as_enum()]))
)
.filter(Expr::col(Column::Id).binary(
BinOper::In,
Expr::tuple([ActiveEnumTrait::as_enum(&Tea::EverydayTea)])
))
.one(db)
.await?
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions tests/partial_model_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use sea_orm::{
prelude::*, sea_query::Alias, DerivePartialModel, FromQueryResult, IntoActiveModel, JoinType,
NotSet, QueryOrder, QuerySelect, Set,
};
use sea_query::ExprTrait;

use crate::common::TestContext;
use common::bakery_chain::*;
Expand Down