This will fail loll
This commit is contained in:
parent
2f0ac4ca1d
commit
afdb1afeb8
4
.github/workflows/rust.yml
vendored
4
.github/workflows/rust.yml
vendored
@ -395,7 +395,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
version: [8.0.27, 5.7.36]
|
version: [8.0, 5.7]
|
||||||
runtime: [async-std, actix, tokio]
|
runtime: [async-std, actix, tokio]
|
||||||
tls: [native-tls]
|
tls: [native-tls]
|
||||||
services:
|
services:
|
||||||
@ -456,7 +456,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
version: [10.6, 10.5, 10.0, 5.5]
|
version: [10.6, 10.5, 10.4]
|
||||||
runtime: [async-std, actix, tokio]
|
runtime: [async-std, actix, tokio]
|
||||||
tls: [native-tls]
|
tls: [native-tls]
|
||||||
services:
|
services:
|
||||||
|
@ -30,7 +30,7 @@ futures-util = { version = "^0.3" }
|
|||||||
log = { version = "^0.4", optional = true }
|
log = { version = "^0.4", optional = true }
|
||||||
rust_decimal = { version = "^1", optional = true }
|
rust_decimal = { version = "^1", optional = true }
|
||||||
sea-orm-macros = { version = "^0.3.1", path = "sea-orm-macros", optional = true }
|
sea-orm-macros = { version = "^0.3.1", path = "sea-orm-macros", optional = true }
|
||||||
sea-query = { version = "^0.18.2", features = ["thread-safe"] }
|
sea-query = { version = "^0.18.2", git = "https://github.com/SeaQL/sea-query.git", branch = "sea-orm/returning", features = ["thread-safe"] }
|
||||||
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
||||||
serde = { version = "^1.0", features = ["derive"] }
|
serde = { version = "^1.0", features = ["derive"] }
|
||||||
serde_json = { version = "^1", optional = true }
|
serde_json = { version = "^1", optional = true }
|
||||||
|
@ -228,7 +228,9 @@ impl<'a> ConnectionTrait<'a> for DatabaseConnection {
|
|||||||
fn support_returning(&self) -> bool {
|
fn support_returning(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
DatabaseConnection::SqlxMySqlPoolConnection { support_returning, .. } => *support_returning,
|
DatabaseConnection::SqlxMySqlPoolConnection {
|
||||||
|
support_returning, ..
|
||||||
|
} => *support_returning,
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
DatabaseConnection::SqlxPostgresPoolConnection(_) => true,
|
DatabaseConnection::SqlxPostgresPoolConnection(_) => true,
|
||||||
#[cfg(feature = "sqlx-sqlite")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
@ -267,27 +269,13 @@ impl DatabaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseConnection {
|
impl DatabaseConnection {
|
||||||
/// Get database version
|
|
||||||
pub fn db_version(&self) -> String {
|
|
||||||
match self {
|
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
|
||||||
DatabaseConnection::SqlxMySqlPoolConnection { version, .. } => version.to_string(),
|
|
||||||
// #[cfg(feature = "sqlx-postgres")]
|
|
||||||
// DatabaseConnection::SqlxPostgresPoolConnection(conn) => ,
|
|
||||||
// #[cfg(feature = "sqlx-sqlite")]
|
|
||||||
// DatabaseConnection::SqlxSqlitePoolConnection(conn) => ,
|
|
||||||
// #[cfg(feature = "mock")]
|
|
||||||
// DatabaseConnection::MockDatabaseConnection(conn) => ,
|
|
||||||
DatabaseConnection::Disconnected => panic!("Disconnected"),
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if database supports `RETURNING`
|
/// Check if database supports `RETURNING`
|
||||||
pub fn db_support_returning(&self) -> bool {
|
pub fn support_returning(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
DatabaseConnection::SqlxMySqlPoolConnection { support_returning, .. } => *support_returning,
|
DatabaseConnection::SqlxMySqlPoolConnection {
|
||||||
|
support_returning, ..
|
||||||
|
} => *support_returning,
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
DatabaseConnection::SqlxPostgresPoolConnection(_) => true,
|
DatabaseConnection::SqlxPostgresPoolConnection(_) => true,
|
||||||
// #[cfg(feature = "sqlx-sqlite")]
|
// #[cfg(feature = "sqlx-sqlite")]
|
||||||
|
@ -43,8 +43,9 @@ where
|
|||||||
let mut query = self.query;
|
let mut query = self.query;
|
||||||
if db.support_returning() && <A::Entity as EntityTrait>::PrimaryKey::iter().count() > 0 {
|
if db.support_returning() && <A::Entity as EntityTrait>::PrimaryKey::iter().count() > 0 {
|
||||||
let mut returning = Query::select();
|
let mut returning = Query::select();
|
||||||
returning
|
returning.columns(
|
||||||
.columns(<A::Entity as EntityTrait>::PrimaryKey::iter().map(|c| c.into_column_ref()));
|
<A::Entity as EntityTrait>::PrimaryKey::iter().map(|c| c.into_column_ref()),
|
||||||
|
);
|
||||||
query.returning(returning);
|
query.returning(returning);
|
||||||
}
|
}
|
||||||
Inserter::<A>::new(self.primary_key, query).exec(db)
|
Inserter::<A>::new(self.primary_key, query).exec(db)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
pub use common::{features::*, setup::*, TestContext};
|
pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||||
use sea_orm::{entity::prelude::*, entity::*, DatabaseConnection};
|
use sea_orm::{entity::prelude::*, *};
|
||||||
|
use sea_query::Query;
|
||||||
|
|
||||||
#[sea_orm_macros::test]
|
#[sea_orm_macros::test]
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
@ -10,27 +11,38 @@ use sea_orm::{entity::prelude::*, entity::*, DatabaseConnection};
|
|||||||
feature = "sqlx-postgres"
|
feature = "sqlx-postgres"
|
||||||
))]
|
))]
|
||||||
async fn main() -> Result<(), DbErr> {
|
async fn main() -> Result<(), DbErr> {
|
||||||
|
use bakery::*;
|
||||||
|
|
||||||
let ctx = TestContext::new("returning_tests").await;
|
let ctx = TestContext::new("returning_tests").await;
|
||||||
let db = &ctx.db;
|
let db = &ctx.db;
|
||||||
|
let builder = db.get_database_backend();
|
||||||
|
|
||||||
match db {
|
let mut insert = Query::insert();
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
insert
|
||||||
DatabaseConnection::SqlxMySqlPoolConnection { .. } => {
|
.into_table(Entity)
|
||||||
let version = db.db_version();
|
.columns(vec![Column::Name, Column::ProfitMargin])
|
||||||
match version.as_str() {
|
.values_panic(vec!["Bakery Shop".into(), 0.5.into()]);
|
||||||
"5.7.26" => assert!(!db.db_support_returning()),
|
|
||||||
_ => unimplemented!("Version {} is not included", version),
|
let mut update = Query::update();
|
||||||
};
|
update
|
||||||
},
|
.table(Entity)
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
.values(vec![
|
||||||
DatabaseConnection::SqlxPostgresPoolConnection(_) => {
|
(Column::Name, "Bakery Shop".into()),
|
||||||
assert!(db.db_support_returning());
|
(Column::ProfitMargin, 0.5.into()),
|
||||||
},
|
])
|
||||||
#[cfg(feature = "sqlx-sqlite")]
|
.and_where(Column::Id.eq(1));
|
||||||
DatabaseConnection::SqlxSqlitePoolConnection(_) => {},
|
|
||||||
_ => unreachable!(),
|
if db.support_returning() {
|
||||||
|
let mut returning = Query::select();
|
||||||
|
returning.columns(vec![Column::Id, Column::Name, Column::ProfitMargin]);
|
||||||
|
insert.returning(returning.clone());
|
||||||
|
update.returning(returning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_tables(db).await?;
|
||||||
|
db.query_one(builder.build(&insert)).await?;
|
||||||
|
db.query_one(builder.build(&update)).await?;
|
||||||
|
assert!(false);
|
||||||
ctx.delete().await;
|
ctx.delete().await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user