Merge branch 'master' into set-if-not-equals

This commit is contained in:
Dmitrii Aleksandrov 2024-05-09 23:08:32 +04:00 committed by GitHub
commit 605ea19672
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
96 changed files with 1201 additions and 676 deletions

View File

@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## 1.0.0-rc.4 - 2024-05-13
### Enhancements
* Added `QueryResult::column_names` https://github.com/SeaQL/sea-orm/pull/2148
* [sea-orm-macro] Add `@generated` in generated code https://github.com/SeaQL/sea-orm/pull/2199
### Upgrades
* Upgrade `sea-query` to `0.31.0-rc.6`
* Upgrade `sea-schema` to `0.15.0-rc.6`
### House Keeping
* Reduce warnings in integration tests https://github.com/SeaQL/sea-orm/pull/2177
## 1.0.0-rc.3 - 2024-03-26
### Enhancements
@ -34,6 +50,8 @@ struct EntityNameNotAIdent {
```
* Added `RelationDef::from_alias()` https://github.com/SeaQL/sea-orm/pull/2146
```rust
let cf = Alias::new("cf");
assert_eq!(
cake::Entity::find()
.join_as(

View File

@ -3,7 +3,7 @@ members = [".", "sea-orm-macros", "sea-orm-codegen"]
[package]
name = "sea-orm"
version = "1.0.0-rc.3"
version = "1.0.0-rc.4"
authors = ["Chris Tsang <chris.2y3@outlook.com>"]
edition = "2021"
description = "🐚 An async & dynamic ORM for Rust"
@ -33,9 +33,9 @@ log = { version = "0.4", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
rust_decimal = { version = "1", default-features = false, optional = true }
bigdecimal = { version = "0.3", default-features = false, optional = true }
sea-orm-macros = { version = "1.0.0-rc.3", path = "sea-orm-macros", default-features = false, features = ["strum"] }
sea-query = { version = "0.31.0-rc.3", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.6.0-rc.1", default-features = false, optional = true }
sea-orm-macros = { version = "1.0.0-rc.4", path = "sea-orm-macros", default-features = false, features = ["strum"] }
sea-query = { version = "0.31.0-rc", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.6.0-rc", default-features = false, optional = true }
strum = { version = "0.26", default-features = false }
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false, optional = true }

View File

@ -13,4 +13,4 @@ serde = { version = "1", features = ["derive"] }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -13,7 +13,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-actix-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"debug-print",
"runtime-async-std-native-tls",

View File

@ -13,4 +13,4 @@ serde = { version = "1", features = ["derive"] }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -13,7 +13,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"debug-print",
"runtime-tokio-native-tls",

View File

@ -16,4 +16,4 @@ version = "5.0.10"
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -14,7 +14,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"debug-print",
"runtime-async-std-native-tls",

View File

@ -13,4 +13,4 @@ serde = { version = "1", features = ["derive"] }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -13,7 +13,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"debug-print",
"runtime-tokio-native-tls",

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ edition = "2021"
[dependencies]
loco-rs = { version = "0.2" }
loco-rs = { version = "0.4" }
migration = { path = "migration" }
serde = { version = "1", features = ["derive"] }
@ -26,8 +26,8 @@ uuid = { version = "1.6.0", features = ["v4"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json"] }
[dependencies.sea-orm]
# path = "../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
path = "../../" # remove this line in your own project
version = "1.0.0-rc.4" # sea-orm version
features = [
"sqlx-sqlite",
"sqlx-postgres",
@ -43,7 +43,7 @@ required-features = []
[dev-dependencies]
serial_test = "2.0.0"
rstest = "0.18.2"
loco-rs = { version = "0.2", features = ["testing"] }
loco-rs = { version = "0.4", features = ["testing"] }
insta = { version = "1.34.0", features = ["redactions", "yaml", "filters"] }
# This allows us to develop using a local version of sea-orm
@ -51,4 +51,3 @@ insta = { version = "1.34.0", features = ["redactions", "yaml", "filters"] }
[patch.crates-io]
sea-orm = { path = "../../" }
sea-orm-migration = { path = "../../sea-orm-migration" }
loco-rs = { git = "https://github.com/billy1624/loco", branch = "sea-orm-v1.0" }

View File

@ -10,11 +10,11 @@ path = "src/lib.rs"
[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }
loco-rs = { version = "0.2" }
loco-rs = { version = "0.4" }
[dependencies.sea-orm-migration]
# path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.

View File

@ -24,11 +24,11 @@ async fn load_item(ctx: &AppContext, id: i32) -> Result<Model> {
item.ok_or_else(|| Error::NotFound)
}
pub async fn list(State(ctx): State<AppContext>) -> Result<Json<Vec<Model>>> {
pub async fn list(State(ctx): State<AppContext>) -> Result<Response> {
format::json(Entity::find().all(&ctx.db).await?)
}
pub async fn add(State(ctx): State<AppContext>, Json(params): Json<Params>) -> Result<Json<Model>> {
pub async fn add(State(ctx): State<AppContext>, Json(params): Json<Params>) -> Result<Response> {
let mut item = ActiveModel {
..Default::default()
};
@ -41,7 +41,7 @@ pub async fn update(
Path(id): Path<i32>,
State(ctx): State<AppContext>,
Json(params): Json<Params>,
) -> Result<Json<Model>> {
) -> Result<Response> {
let item = load_item(&ctx, id).await?;
let mut item = item.into_active_model();
params.update(&mut item);
@ -49,12 +49,12 @@ pub async fn update(
format::json(item)
}
pub async fn remove(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Result<()> {
pub async fn remove(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Result<Response> {
load_item(&ctx, id).await?.delete(&ctx.db).await?;
format::empty()
}
pub async fn get_one(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Result<Json<Model>> {
pub async fn get_one(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Result<Response> {
format::json(load_item(&ctx, id).await?)
}

View File

@ -13,4 +13,4 @@ serde = { version = "1", features = ["derive"] }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -13,7 +13,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"debug-print",
"runtime-async-std-native-tls",

View File

@ -13,4 +13,4 @@ rocket = { version = "0.5.0", features = ["json"] }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -14,7 +14,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"runtime-tokio-native-tls",
"sqlx-postgres",

View File

@ -13,7 +13,7 @@ rocket = { version = "0.5.0", features = ["json"] }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
[dependencies.rocket_okapi]
version = "0.8.0"

View File

@ -14,7 +14,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"runtime-tokio-native-tls",
# "sqlx-postgres",

View File

@ -14,4 +14,4 @@ salvo = { version = "0.50" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -13,7 +13,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-native-tls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"debug-print",
"runtime-tokio-native-tls",

View File

@ -25,7 +25,7 @@ cargo run
## Install Seaography
```sh
cargo install seaography-cli@^1.0.0-rc.2
cargo install seaography-cli@^1.0.0-rc.3
```
## Generate GraphQL project

View File

@ -5,19 +5,19 @@ version = "0.3.0"
publish = false
[dependencies]
poem = { version = "1.3.56" }
async-graphql-poem = { version = "5.0.10" }
async-graphql = { version = "5.0.10", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
poem = { version = "3.0" }
async-graphql-poem = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
async-trait = { version = "0.1.72" }
dotenv = "0.15.0"
sea-orm = { version = "0.12.0", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] }
sea-orm = { path = "../../../", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
lazy_static = { version = "1.4.0" }
[dependencies.seaography]
version = "1.0.0-rc.2" # seaography version
version = "1.0.0-rc.3" # seaography version
features = ["with-decimal", "with-chrono"]
[dev-dependencies]
@ -25,3 +25,8 @@ serde_json = { version = "1.0.103" }
[workspace]
members = []
# This allows us to develop using a local version of sea-orm
# remove this section in your own project
[patch.crates-io]
sea-orm = { path = "../../../" }

View File

@ -11,7 +11,7 @@ pub fn schema(
depth: Option<usize>,
complexity: Option<usize>,
) -> Result<Schema, SchemaError> {
let mut builder = Builder::new(&CONTEXT);
let mut builder = Builder::new(&CONTEXT, database.clone());
seaography::register_entities!(builder, [baker, bakery, cake, cake_baker,]);
let schema = builder.schema_builder();
let schema = if let Some(depth) = depth {

View File

@ -14,12 +14,12 @@ path = "src/lib.rs"
async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm]
path = "../../.." # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.4" # sea-orm version
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
"runtime-async-std-native-tls",
"sqlx-mysql",

View File

@ -13,4 +13,4 @@ serde = { version = "1", features = ["derive"] }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version

View File

@ -13,7 +13,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
path = "../../../sea-orm-migration" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm-migration version
version = "1.0.0-rc.4" # sea-orm-migration version
features = [
# Enable following runtime and db backend features if you want to run migration via CLI
# "runtime-tokio-rustls",

View File

@ -10,7 +10,7 @@ entity = { path = "../entity" }
[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
version = "1.0.0-rc.3" # sea-orm version
version = "1.0.0-rc.4" # sea-orm version
features = [
"debug-print",
"runtime-tokio-rustls",

View File

@ -3,7 +3,7 @@
[package]
name = "sea-orm-cli"
version = "1.0.0-rc.3"
version = "1.0.0-rc.4"
authors = [
"Chris Tsang <chris.2y3@outlook.com>",
"Billy Chan <ccw.billy.123@gmail.com>",
@ -37,8 +37,8 @@ required-features = ["cli", "codegen"]
clap = { version = "4.3", features = ["env", "derive"], optional = true }
dotenvy = { version = "0.15", default-features = false, optional = true }
async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], optional = true }
sea-orm-codegen = { version = "=1.0.0-rc.3", path = "../sea-orm-codegen", default-features = false, optional = true }
sea-schema = { version = "0.15.0-rc.4" }
sea-orm-codegen = { version = "=1.0.0-rc.4", path = "../sea-orm-codegen", default-features = false, optional = true }
sea-schema = { version = "0.15.0-rc" }
sqlx = { version = "0.7", default-features = false, features = ["mysql", "postgres"], optional = true }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
tracing = { version = "0.1", default-features = false }

View File

@ -1,6 +1,6 @@
[package]
name = "sea-orm-codegen"
version = "1.0.0-rc.3"
version = "1.0.0-rc.4"
authors = ["Billy Chan <ccw.billy.123@gmail.com>"]
edition = "2021"
description = "Code Generator for SeaORM"
@ -17,7 +17,7 @@ name = "sea_orm_codegen"
path = "src/lib.rs"
[dependencies]
sea-query = { version = "0.31.0-rc.3", default-features = false, features = ["thread-safe"] }
sea-query = { version = "0.31.0-rc", default-features = false, features = ["thread-safe"] }
syn = { version = "2", default-features = false, features = ["parsing", "proc-macro", "derive", "printing"] }
quote = { version = "1", default-features = false }
heck = { version = "0.4", default-features = false }

View File

@ -69,7 +69,9 @@ impl Column {
},
ColumnType::Decimal(_) | ColumnType::Money(_) => "Decimal".to_owned(),
ColumnType::Uuid => "Uuid".to_owned(),
ColumnType::Binary(_) | ColumnType::VarBinary(_) => "Vec<u8>".to_owned(),
ColumnType::Binary(_) | ColumnType::VarBinary(_) | ColumnType::Blob => {
"Vec<u8>".to_owned()
}
ColumnType::Boolean => "bool".to_owned(),
ColumnType::Enum { name, .. } => name.to_string().to_upper_camel_case(),
ColumnType::Array(column_type) => {
@ -102,6 +104,7 @@ impl Column {
StringLen::None => Some("VarBinary(StringLen::None)".to_owned()),
StringLen::Max => Some("VarBinary(StringLen::Max)".to_owned()),
},
ColumnType::Blob => Some("Blob".to_owned()),
_ => None,
};
col_type.map(|ty| quote! { column_type = #ty })
@ -149,6 +152,7 @@ impl Column {
StringLen::None => quote! { ColumnType::VarBinary(StringLen::None) },
StringLen::Max => quote! { ColumnType::VarBinary(StringLen::Max) },
},
ColumnType::Blob => quote! { ColumnType::Blob },
ColumnType::Boolean => quote! { ColumnType::Boolean },
ColumnType::Money(s) => match s {
Some((s1, s2)) => quote! { ColumnType::Money(Some((#s1, #s2))) },

View File

@ -154,7 +154,7 @@ impl EntityTransformer {
RelationType::HasMany
};
rel.rel_type = rel_type;
rel.ref_table = table_name.clone();
rel.ref_table = table_name.to_string();
rel.columns = Vec::new();
rel.ref_columns = Vec::new();
if let Some(vec) = inverse_relations.get_mut(&ref_table) {

View File

@ -330,7 +330,7 @@ impl EntityWriter {
pub fn write_doc_comment(lines: &mut Vec<String>) {
let ver = env!("CARGO_PKG_VERSION");
let comments = vec![format!(
"//! `SeaORM` Entity. Generated by sea-orm-codegen {ver}"
"//! `SeaORM` Entity, @generated by sea-orm-codegen {ver}"
)];
lines.extend(comments);
lines.push("".to_owned());

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod duplicated_many_to_many_paths;
pub mod many_to_many;
pub mod many_to_many_multiple;

View File

@ -1,6 +1,6 @@
[package]
name = "sea-orm-macros"
version = "1.0.0-rc.3"
version = "1.0.0-rc.4"
authors = [ "Billy Chan <ccw.billy.123@gmail.com>" ]
edition = "2021"
description = "Derive macros for SeaORM"

View File

@ -7,6 +7,7 @@ pub mod derive_attr {
pub column: Option<syn::Ident>,
pub entity: Option<syn::Ident>,
pub model: Option<syn::Ident>,
pub active_model: Option<syn::Ident>,
pub primary_key: Option<syn::Ident>,
pub relation: Option<syn::Ident>,
pub schema_name: Option<syn::Lit>,

View File

@ -9,6 +9,7 @@ struct DeriveEntity {
column_ident: syn::Ident,
ident: syn::Ident,
model_ident: syn::Ident,
active_model_ident: syn::Ident,
primary_key_ident: syn::Ident,
relation_ident: syn::Ident,
schema_name: Option<syn::Lit>,
@ -22,6 +23,9 @@ impl DeriveEntity {
let ident = input.ident;
let column_ident = sea_attr.column.unwrap_or_else(|| format_ident!("Column"));
let model_ident = sea_attr.model.unwrap_or_else(|| format_ident!("Model"));
let active_model_ident = sea_attr
.active_model
.unwrap_or_else(|| format_ident!("ActiveModel"));
let primary_key_ident = sea_attr
.primary_key
.unwrap_or_else(|| format_ident!("PrimaryKey"));
@ -36,6 +40,7 @@ impl DeriveEntity {
column_ident,
ident,
model_ident,
active_model_ident,
primary_key_ident,
relation_ident,
schema_name,
@ -87,6 +92,7 @@ impl DeriveEntity {
let Self {
ident,
model_ident,
active_model_ident,
column_ident,
primary_key_ident,
relation_ident,
@ -98,6 +104,8 @@ impl DeriveEntity {
impl sea_orm::entity::EntityTrait for #ident {
type Model = #model_ident;
type ActiveModel = #active_model_ident;
type Column = #column_ident;
type PrimaryKey = #primary_key_ident;

View File

@ -1,4 +1,6 @@
//! Source code adapted from https://github.com/Peternator7/strum
#![allow(dead_code)]
pub mod enum_iter;
pub mod helpers;

View File

@ -3,7 +3,7 @@
[package]
name = "sea-orm-migration"
version = "1.0.0-rc.3"
version = "1.0.0-rc.4"
authors = ["Billy Chan <ccw.billy.123@gmail.com>"]
edition = "2021"
description = "Migration utility for SeaORM"
@ -23,9 +23,9 @@ path = "src/lib.rs"
async-trait = { version = "0.1", default-features = false }
clap = { version = "4.3", features = ["env", "derive"], optional = true }
dotenvy = { version = "0.15", default-features = false, optional = true }
sea-orm = { version = "1.0.0-rc.3", path = "../", default-features = false, features = ["macros"] }
sea-orm-cli = { version = "1.0.0-rc.3", path = "../sea-orm-cli", default-features = false, optional = true }
sea-schema = { version = "0.15.0-rc.4" }
sea-orm = { version = "1.0.0-rc.4", path = "../", default-features = false, features = ["macros"] }
sea-orm-cli = { version = "1.0.0-rc.4", path = "../sea-orm-cli", default-features = false, optional = true }
sea-schema = { version = "0.15.0-rc" }
tracing = { version = "0.1", default-features = false, features = ["log"] }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
futures = { version = "0.3", default-features = false, features = ["std"] }

View File

@ -1,5 +1,6 @@
use crate::{
error::*, ConnectionTrait, DeleteResult, EntityTrait, Iterable, PrimaryKeyToColumn, Value,
error::*, ConnectionTrait, DeleteResult, EntityTrait, Iterable, PrimaryKeyArity,
PrimaryKeyToColumn, PrimaryKeyTrait, Value,
};
use async_trait::async_trait;
use sea_query::{Nullable, ValueTuple};
@ -139,7 +140,7 @@ pub trait ActiveModelTrait: Clone + Debug {
}
};
}
match <Self::Entity as EntityTrait>::PrimaryKey::iter().count() {
match <<<Self::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY {
1 => {
let s1 = next!();
Some(ValueTuple::One(s1))
@ -886,6 +887,26 @@ where
_ => *self = ActiveValue::Set(value),
}
}
/// Get the inner value, unless `self` is [NotSet][ActiveValue::NotSet].
///
/// There's also a panicking version: [ActiveValue::as_ref].
///
/// ## Examples
///
/// ```
/// # use sea_orm::ActiveValue;
/// #
/// assert_eq!(ActiveValue::Unchanged(42).try_as_ref(), Some(&42));
/// assert_eq!(ActiveValue::Set(42).try_as_ref(), Some(&42));
/// assert_eq!(ActiveValue::NotSet.try_as_ref(), None::<&i32>);
/// ```
pub fn try_as_ref(&self) -> Option<&V> {
match self {
ActiveValue::Set(value) | ActiveValue::Unchanged(value) => Some(value),
ActiveValue::NotSet => None,
}
}
}
impl<V> std::convert::AsRef<V> for ActiveValue<V>
@ -894,7 +915,9 @@ where
{
/// # Panics
///
/// Panics if it is [ActiveValue::NotSet]
/// Panics if it is [ActiveValue::NotSet].
///
/// See [ActiveValue::try_as_ref] for a fallible non-panicking version.
fn as_ref(&self) -> &V {
match self {
ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,

View File

@ -1,7 +1,7 @@
use crate::{
ActiveModelTrait, ColumnTrait, Delete, DeleteMany, DeleteOne, FromQueryResult, Insert,
ModelTrait, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, Related, RelationBuilder,
RelationTrait, RelationType, Select, Update, UpdateMany, UpdateOne,
ActiveModelBehavior, ActiveModelTrait, ColumnTrait, Delete, DeleteMany, DeleteOne,
FromQueryResult, Insert, ModelTrait, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, Related,
RelationBuilder, RelationTrait, RelationType, Select, Update, UpdateMany, UpdateOne,
};
use sea_query::{Alias, Iden, IntoIden, IntoTableRef, IntoValueTuple, TableRef};
use std::fmt::Debug;
@ -58,6 +58,9 @@ pub trait EntityTrait: EntityName {
#[allow(missing_docs)]
type Model: ModelTrait<Entity = Self> + FromQueryResult;
#[allow(missing_docs)]
type ActiveModel: ActiveModelBehavior<Entity = Self>;
#[allow(missing_docs)]
type Column: ColumnTrait;

View File

@ -4,8 +4,8 @@ pub use crate::{
ActiveEnum, ActiveModelBehavior, ActiveModelTrait, ColumnDef, ColumnTrait, ColumnType,
ColumnTypeTrait, ConnectionTrait, CursorTrait, DatabaseConnection, DbConn, EntityName,
EntityTrait, EnumIter, ForeignKeyAction, Iden, IdenStatic, Linked, LoaderTrait, ModelTrait,
PaginatorTrait, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, QueryResult, Related,
RelationDef, RelationTrait, Select, Value,
PaginatorTrait, PrimaryKeyArity, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, QueryResult,
Related, RelationDef, RelationTrait, Select, Value,
};
#[cfg(feature = "macros")]

View File

@ -46,9 +46,10 @@ pub trait PrimaryKeyTrait: IdenStatic + Iterable {
+ IntoValueTuple
+ FromValueTuple
+ TryGetableMany
+ TryFromU64;
+ TryFromU64
+ PrimaryKeyArity;
/// Method to call to perform `AUTOINCREMENT` operation on a Primary Kay
/// Method to call to perform `AUTOINCREMENT` operation on a Primary Key
fn auto_increment() -> bool;
}
@ -66,6 +67,40 @@ pub trait PrimaryKeyToColumn {
Self: Sized;
}
/// How many columns this Primary Key comprises
pub trait PrimaryKeyArity {
/// Arity of the Primary Key
const ARITY: usize;
}
impl<V> PrimaryKeyArity for V
where
V: crate::TryGetable,
{
const ARITY: usize = 1;
}
macro_rules! impl_pk_arity {
($len:expr, $($tuple_arg:ident),*) => {
impl<$($tuple_arg: crate::TryGetableMany,)*> PrimaryKeyArity for ($($tuple_arg,)*) {
const ARITY: usize = $len;
}
}
}
impl_pk_arity!(1, T1);
impl_pk_arity!(2, T1, T2);
impl_pk_arity!(3, T1, T2, T3);
impl_pk_arity!(4, T1, T2, T3, T4);
impl_pk_arity!(5, T1, T2, T3, T4, T5);
impl_pk_arity!(6, T1, T2, T3, T4, T5, T6);
impl_pk_arity!(7, T1, T2, T3, T4, T5, T6, T7);
impl_pk_arity!(8, T1, T2, T3, T4, T5, T6, T7, T8);
impl_pk_arity!(9, T1, T2, T3, T4, T5, T6, T7, T8, T9);
impl_pk_arity!(10, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
impl_pk_arity!(11, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11);
impl_pk_arity!(12, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12);
#[cfg(test)]
mod tests {
#[test]

View File

@ -116,7 +116,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 {
if db.support_returning() {
let db_backend = db.get_database_backend();
let returning =
Query::returning().exprs(<A::Entity as EntityTrait>::PrimaryKey::iter().map(|c| {

View File

@ -115,6 +115,41 @@ impl QueryResult {
{
Ok(T::try_get_many_by_index(self)?)
}
/// Retrieves the names of the columns in the result set
pub fn column_names(&self) -> Vec<String> {
#[cfg(feature = "sqlx-dep")]
use sqlx::Column;
match &self.row {
#[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => {
row.columns().iter().map(|c| c.name().to_string()).collect()
}
#[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => {
row.columns().iter().map(|c| c.name().to_string()).collect()
}
#[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(row) => {
row.columns().iter().map(|c| c.name().to_string()).collect()
}
#[cfg(feature = "mock")]
QueryResultRow::Mock(row) => row
.clone()
.into_column_value_tuples()
.map(|(c, _)| c.to_string())
.collect(),
#[cfg(feature = "proxy")]
QueryResultRow::Proxy(row) => row
.clone()
.into_column_value_tuples()
.map(|(c, _)| c.to_string())
.collect(),
#[allow(unreachable_patterns)]
_ => unreachable!(),
}
}
}
#[allow(unused_variables)]
@ -1258,8 +1293,11 @@ try_from_u64_err!(uuid::Uuid);
#[cfg(test)]
mod tests {
use super::TryGetError;
use crate::error::*;
use std::collections::BTreeMap;
use sea_query::Value;
use super::*;
#[test]
fn from_try_get_error() {
@ -1347,4 +1385,21 @@ mod tests {
)
);
}
#[test]
fn column_names_from_query_result() {
let mut values = BTreeMap::new();
values.insert("id".to_string(), Value::Int(Some(1)));
values.insert(
"name".to_string(),
Value::String(Some(Box::new("Abc".to_owned()))),
);
let query_result = QueryResult {
row: QueryResultRow::Mock(crate::MockRow { values }),
};
assert_eq!(
query_result.column_names(),
vec!["id".to_owned(), "name".to_owned()]
);
}
}

View File

@ -1,7 +1,8 @@
use crate::{
error::*, ConnectionTrait, DbBackend, EntityTrait, FromQueryResult, IdenStatic, Iterable,
ModelTrait, PartialModelTrait, PrimaryKeyToColumn, QueryResult, QuerySelect, Select, SelectA,
SelectB, SelectTwo, SelectTwoMany, Statement, StreamTrait, TryGetableMany,
ModelTrait, PartialModelTrait, PrimaryKeyArity, PrimaryKeyToColumn, PrimaryKeyTrait,
QueryResult, QuerySelect, Select, SelectA, SelectB, SelectTwo, SelectTwoMany, Statement,
StreamTrait, TryGetableMany,
};
use futures::{Stream, TryStreamExt};
use sea_query::{SelectStatement, Value};
@ -990,6 +991,7 @@ where
}
}
#[allow(clippy::unwrap_used)]
fn consolidate_query_result<L, R>(
rows: Vec<(L::Model, Option<R::Model>)>,
) -> Vec<(L::Model, Vec<R::Model>)>
@ -997,15 +999,26 @@ where
L: EntityTrait,
R: EntityTrait,
{
// This is a strong point to consider adding a trait associated constant
// to PrimaryKeyTrait to indicate the arity
let pkcol: Vec<_> = <L::PrimaryKey as Iterable>::iter()
match <<L::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY {
1 => {
let col = <L::PrimaryKey as Iterable>::iter()
.next()
.unwrap()
.into_column();
consolidate_query_result_of::<L, R, UnitPk<L>>(rows, UnitPk(col))
}
2 => {
let mut iter = <L::PrimaryKey as Iterable>::iter();
let col1 = iter.next().unwrap().into_column();
let col2 = iter.next().unwrap().into_column();
consolidate_query_result_of::<L, R, PairPk<L>>(rows, PairPk(col1, col2))
}
_ => {
let cols: Vec<_> = <L::PrimaryKey as Iterable>::iter()
.map(|pk| pk.into_column())
.collect();
if pkcol.len() == 1 {
consolidate_query_result_of::<L, R, UnitPk<L>>(rows, UnitPk(pkcol[0]))
} else {
consolidate_query_result_of::<L, R, TuplePk<L>>(rows, TuplePk(pkcol))
consolidate_query_result_of::<L, R, TuplePk<L>>(rows, TuplePk(cols))
}
}
}
@ -1014,8 +1027,9 @@ trait ModelKey<E: EntityTrait> {
fn get(&self, model: &E::Model) -> Self::Type;
}
// This could have been an array of [E::Column; <E::PrimaryKey as PrimaryKeyTrait>::ARITY]
// This could have been an array of [E::Column; <E::PrimaryKey as PrimaryKeyTrait>::ARITY], but it still doesn't compile
struct UnitPk<E: EntityTrait>(E::Column);
struct PairPk<E: EntityTrait>(E::Column, E::Column);
struct TuplePk<E: EntityTrait>(Vec<E::Column>);
impl<E: EntityTrait> ModelKey<E> for UnitPk<E> {
@ -1025,6 +1039,13 @@ impl<E: EntityTrait> ModelKey<E> for UnitPk<E> {
}
}
impl<E: EntityTrait> ModelKey<E> for PairPk<E> {
type Type = (Value, Value);
fn get(&self, model: &E::Model) -> Self::Type {
(model.get(self.0), model.get(self.1))
}
}
impl<E: EntityTrait> ModelKey<E> for TuplePk<E> {
type Type = Vec<Value>;
fn get(&self, model: &E::Model) -> Self::Type {
@ -1054,8 +1075,8 @@ where
} else {
acc.insert(key, vec![value]);
}
} else if acc.get(&key).is_none() {
acc.insert(key, vec![]);
} else {
acc.entry(key).or_default();
}
acc

View File

@ -284,7 +284,7 @@ pub trait QuerySelect: Sized {
/// Add an AND HAVING expression
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
/// use sea_orm::{sea_query::{Alias, Expr}, entity::*, query::*, tests_cfg::cake, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
@ -301,10 +301,10 @@ pub trait QuerySelect: Sized {
/// .column_as(cake::Column::Id.count(), "count")
/// .column_as(cake::Column::Id.sum(), "sum_of_id")
/// .group_by(cake::Column::Name)
/// .having(cake::Column::Id.gt(6))
/// .having(Expr::col(Alias::new("count")).gt(6))
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT COUNT(`cake`.`id`) AS `count`, SUM(`cake`.`id`) AS `sum_of_id` FROM `cake` GROUP BY `cake`.`name` HAVING `cake`.`id` > 6"
/// "SELECT COUNT(`cake`.`id`) AS `count`, SUM(`cake`.`id`) AS `sum_of_id` FROM `cake` GROUP BY `cake`.`name` HAVING `count` > 6"
/// );
/// ```
fn having<F>(mut self, filter: F) -> Self

View File

@ -1,6 +1,6 @@
use crate::{
ActiveEnum, ColumnTrait, ColumnType, DbBackend, EntityTrait, Iterable, PrimaryKeyToColumn,
PrimaryKeyTrait, RelationTrait, Schema,
ActiveEnum, ColumnTrait, ColumnType, DbBackend, EntityTrait, Iterable, PrimaryKeyArity,
PrimaryKeyToColumn, PrimaryKeyTrait, RelationTrait, Schema,
};
use sea_query::{
extension::postgres::{Type, TypeCreateStatement},
@ -172,7 +172,7 @@ where
stmt.col(&mut column_def);
}
if E::PrimaryKey::iter().count() > 1 {
if <<E::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY > 1 {
let mut idx_pk = Index::create();
for primary_key in E::PrimaryKey::iter() {
idx_pk.col(primary_key);
@ -228,7 +228,7 @@ where
if E::PrimaryKey::auto_increment() {
column_def.auto_increment();
}
if E::PrimaryKey::iter().count() == 1 {
if <<E::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY == 1 {
column_def.primary_key();
}
}

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
//! Configurations for test cases and examples. Not intended for actual use.
pub mod cake;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
use active_enum::Entity as ActiveEnumEntity;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use sea_orm::{entity::*, error::*, query::*, sea_query, tests_cfg::*, Database, DbConn};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
use common::features::*;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
mod crud;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use sea_orm::{entity::prelude::*, DatabaseConnection, IntoActiveModel};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use sea_orm::entity::prelude::*;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
mod crud;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
@ -86,7 +88,7 @@ pub async fn insert_json_struct_vec_derive(db: &DatabaseConnection) -> Result<()
],
};
let result = json_vec.clone().into_active_model().insert(db).await?;
let _result = json_vec.clone().into_active_model().insert(db).await?;
let model = json_vec_derive::json_struct_vec::Entity::find()
.filter(json_vec_derive::json_struct_vec::Column::Id.eq(json_vec.id))

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
use entity::{Column, Entity};
use sea_orm::{ColumnTrait, DerivePartialModel, EntityTrait, FromQueryResult, ModelTrait};
use sea_query::Expr;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use chrono::offset::Utc;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,10 +1,12 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use chrono::offset::Utc;
pub use common::{bakery_chain::*, setup::*, TestContext};
pub use rust_decimal::prelude::*;
pub use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
pub use uuid::Uuid;
use chrono::offset::Utc;
use common::{bakery_chain::*, setup::*, TestContext};
use rust_decimal::prelude::*;
use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
use uuid::Uuid;
// Run the test locally:
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};
pub use sea_orm::{

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use pretty_assertions::assert_eq;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use pretty_assertions::assert_eq;

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
use sea_orm::{IntoActiveValue, TryFromU64, TryGetable, Value};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};

View File

@ -1,3 +1,5 @@
#![allow(unused_imports, dead_code)]
pub mod common;
use std::sync::Arc;