From c5468eb92f01324c248585990bc8196c6f5eab40 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 5 Nov 2021 12:41:49 +0800 Subject: [PATCH] Use "marlon-sousa/sea-query" --- Cargo.toml | 2 +- src/executor/insert.rs | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4244c305..db5abc69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ futures-util = { version = "^0.3" } log = { version = "^0.4", optional = true } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.3.1", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.18.0", features = ["thread-safe"] } +sea-query = { version = "^0.18.0", git = "https://github.com/marlon-sousa/sea-query.git", branch = "extended-returning-support", features = ["thread-safe"] } sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1", optional = true } diff --git a/src/executor/insert.rs b/src/executor/insert.rs index 64b6c145..8e97ccbc 100644 --- a/src/executor/insert.rs +++ b/src/executor/insert.rs @@ -1,8 +1,8 @@ use crate::{ - error::*, ActiveModelTrait, ConnectionTrait, DbBackend, EntityTrait, Insert, PrimaryKeyTrait, - Statement, TryFromU64, + error::*, ActiveModelTrait, ConnectionTrait, DbBackend, EntityTrait, Insert, Iterable, + PrimaryKeyTrait, Statement, TryFromU64, }; -use sea_query::{FromValueTuple, InsertStatement, ValueTuple}; +use sea_query::{FromValueTuple, InsertStatement, IntoColumnRef, Returning, ValueTuple}; use std::{future::Future, marker::PhantomData}; /// Defines a structure to perform INSERT operations in an ActiveModel @@ -39,15 +39,14 @@ where { // so that self is dropped before entering await let mut query = self.query; - if db.get_database_backend() == DbBackend::Postgres { - use crate::{sea_query::Query, Iterable}; - if ::PrimaryKey::iter().count() > 0 { - query.returning( - Query::select() - .columns(::PrimaryKey::iter()) - .take(), - ); - } + if db.get_database_backend() == DbBackend::Postgres + && ::PrimaryKey::iter().count() > 0 + { + query.returning(Returning::Columns( + ::PrimaryKey::iter() + .map(|c| c.into_column_ref()) + .collect(), + )); } Inserter::::new(self.primary_key, query).exec(db) }