Skip to content

Commit

Permalink
Merge remote-tracking branch 'root/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
anshap1719 committed Mar 11, 2024
2 parents 00a47d8 + f0724c4 commit 7ed40c1
Show file tree
Hide file tree
Showing 86 changed files with 1,342 additions and 1,400 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ jobs:
examples/poem_example,
examples/proxy_gluesql_example,
examples/rocket_example,
# examples/rocket_okapi_example,
examples/rocket_okapi_example,
examples/salvo_example,
examples/seaography_example,
examples/tonic_example,
Expand Down
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,51 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Breaking Changes

* Updated Strum to version 0.26 https://github.com/SeaQL/sea-orm/pull/2088
* Renamed `ConnectOptions::pool_options()` to `ConnectOptions::sqlx_pool_options()` https://github.com/SeaQL/sea-orm/pull/2145
* Made `sqlx_common` private, hiding `sqlx_error_to_xxx_err` https://github.com/SeaQL/sea-orm/pull/2145

### Enhancements

* [sea-orm-cli] Fix `migrate generate` on empty `mod.rs` files
* `DerivePartialModel` macro attribute `entity` now supports `syn::Type` https://github.com/SeaQL/sea-orm/pull/2137
```rust
#[derive(DerivePartialModel)]
#[sea_orm(entity = "<entity::Model as ModelTrait>::Entity")]
struct EntityNameNotAIdent {
#[sea_orm(from_col = "foo2")]
_foo: i32,
#[sea_orm(from_col = "bar2")]
_bar: String,
}
```
* Added `RelationDef::from_alias()` https://github.com/SeaQL/sea-orm/pull/2146
```rust
assert_eq!(
cake::Entity::find()
.join_as(
JoinType::LeftJoin,
cake_filling::Relation::Cake.def().rev(),
cf.clone()
)
.join(
JoinType::LeftJoin,
cake_filling::Relation::Filling.def().from_alias(cf)
)
.build(DbBackend::MySql)
.to_string(),
[
"SELECT `cake`.`id`, `cake`.`name` FROM `cake`",
"LEFT JOIN `cake_filling` AS `cf` ON `cake`.`id` = `cf`.`cake_id`",
"LEFT JOIN `filling` ON `cf`.`filling_id` = `filling`.`id`",
]
.join(" ")
);
```

### House keeping

* Improved Actix example to return 404 not found on unexpected inputs https://github.com/SeaQL/sea-orm/pull/2140
* Re-enable `rocket_okapi` example https://github.com/SeaQL/sea-orm/pull/2136

## 1.0.0-rc.1 - 2024-02-06

Expand Down
30 changes: 20 additions & 10 deletions examples/actix_example/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,34 @@ async fn create(
.finish())
}

#[get("/{id}")]
#[get(r#"/{id:\d+}"#)]
async fn edit(data: web::Data<AppState>, id: web::Path<i32>) -> Result<HttpResponse, Error> {
let conn = &data.conn;
let template = &data.templates;
let id = id.into_inner();

let post: post::Model = Query::find_post_by_id(conn, id)
let post: Option<post::Model> = Query::find_post_by_id(conn, id)
.await
.expect("could not find post")
.unwrap_or_else(|| panic!("could not find post with id {id}"));
.expect("could not find post");

let mut ctx = tera::Context::new();
ctx.insert("post", &post);

let body = template
.render("edit.html.tera", &ctx)
.map_err(|_| error::ErrorInternalServerError("Template error"))?;
Ok(HttpResponse::Ok().content_type("text/html").body(body))
let body = match post {
Some(post) => {
ctx.insert("post", &post);

template
.render("edit.html.tera", &ctx)
.map_err(|_| error::ErrorInternalServerError("Template error"))
}
None => {
ctx.insert("uri", &format!("/{}", id));

template
.render("error/404.html.tera", &ctx)
.map_err(|_| error::ErrorInternalServerError("Template error"))
}
};
Ok(HttpResponse::Ok().content_type("text/html").body(body?))
}

#[post("/{id}")]
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/src/example_filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(None).def(),
Self::Name => ColumnType::String(StringLen::None).def(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/src/example_fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(None).def(),
Self::Name => ColumnType::String(StringLen::None).def(),
Self::CakeId => ColumnType::Integer.def(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/rocket_okapi_example/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Rocket and Rocket-API with SeaORM example app

1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database
1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database (or leave it as-is to use in-memory SQLite)

1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)
1. If not using the SQLite DB: turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)

1. Execute `cargo run` to start the server

Expand Down
6 changes: 5 additions & 1 deletion examples/rocket_okapi_example/Rocket.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ template_dir = "api/templates/"

# Postgres
# make sure to enable "sqlx-postgres" feature in Cargo.toml, i.e default = ["sqlx-postgres"]
url = "postgres://user:pass@localhost:5432/rocket"
# url = "postgres://user:pass@localhost:5432/rocket"

# SQLite
# make sure to enable "sqlx-sqlite" feature in Cargo.toml, i.e default = ["sqlx-sqlite"]
url = "sqlite::memory:"
11 changes: 2 additions & 9 deletions examples/rocket_okapi_example/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ rocket-okapi-example-service = { path = "../service" }
futures = { version = "0.3" }
futures-util = { version = "0.3" }
rocket = { version = "0.5.0", features = ["json"] }
rocket_cors = "0.6.0"
rocket_dyn_templates = { version = "0.1.0-rc.1", features = ["tera"] }
rocket_okapi = { version = "0.8.0", features = ["swagger", "rapidoc", "rocket_db_pools"] }
serde_json = { version = "1" }
entity = { path = "../entity" }
migration = { path = "../migration" }
Expand All @@ -26,12 +28,3 @@ features = [
"rocket_okapi",
] # enables rocket_okapi so to have open api features enabled
# version = "0.5"

[dependencies.rocket_okapi]
version = "0.8.0-rc.2"
features = ["swagger", "rapidoc", "rocket_db_pools"]

[dependencies.rocket_cors]
git = "https://github.com/lawliet89/rocket_cors.git"
rev = "54fae070"
default-features = false
1 change: 0 additions & 1 deletion examples/rocket_okapi_example/api/src/okapi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::pool;
use pool::Db;

pub use entity::post;
pub use entity::post::Entity as Post;

use rocket_okapi::settings::OpenApiSettings;

Expand Down
2 changes: 1 addition & 1 deletion examples/rocket_okapi_example/dto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ rocket = { version = "0.5.0", features = ["json"] }
path = "../entity"

[dependencies.rocket_okapi]
version = "0.8.0-rc.2"
version = "0.8.0"
2 changes: 1 addition & 1 deletion examples/rocket_okapi_example/entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ path = "../../../" # remove this line in your own project
version = "1.0.0-rc.1" # sea-orm version

[dependencies.rocket_okapi]
version = "0.8.0-rc.2"
version = "0.8.0"
6 changes: 3 additions & 3 deletions examples/rocket_okapi_example/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ path = "../../../" # remove this line in your own project
version = "1.0.0-rc.1" # sea-orm version
features = [
"runtime-tokio-native-tls",
"sqlx-postgres",
# "sqlx-mysql",
# "sqlx-sqlite",
# "sqlx-postgres",
# "sqlx-mysql",
"sqlx-sqlite",
]

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion issues/1143/src/entity/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use sea_orm::entity::prelude::*;

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "string(Some(1))")]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(1))")]
pub enum Category {
#[sea_orm(string_value = "B")]
Big,
Expand Down
2 changes: 1 addition & 1 deletion issues/1599/entity/src/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(None).def(),
Self::Name => ColumnType::String(StringLen::None).def(),
Self::VendorId => ColumnType::Integer.def().nullable(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-codegen/src/entity/base_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Entity {
#[cfg(test)]
mod tests {
use quote::{format_ident, quote};
use sea_query::{ColumnType, ForeignKeyAction};
use sea_query::{ColumnType, ForeignKeyAction, StringLen};

use crate::{Column, DateTimeCrate, Entity, PrimaryKey, Relation, RelationType};

Expand All @@ -284,7 +284,7 @@ mod tests {
},
Column {
name: "name".to_owned(),
col_type: ColumnType::string(None),
col_type: ColumnType::String(StringLen::None),
auto_increment: false,
not_null: false,
unique: false,
Expand Down
14 changes: 7 additions & 7 deletions sea-orm-codegen/src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl Column {
None => quote! { ColumnType::Char(None) },
},
ColumnType::String(s) => match s {
StringLen::N(s) => quote! { ColumnType::string(Some(#s)) },
StringLen::None => quote! { ColumnType::string(None) },
StringLen::N(s) => quote! { ColumnType::String(StringLen::N(#s)) },
StringLen::None => quote! { ColumnType::String(StringLen::None) },
StringLen::Max => quote! { ColumnType::String(StringLen::Max) },
},
ColumnType::Text => quote! { ColumnType::Text },
Expand Down Expand Up @@ -302,8 +302,8 @@ mod tests {
};
}
vec![
make_col!("id", ColumnType::string(Some(255))),
make_col!("id", ColumnType::string(None)),
make_col!("id", ColumnType::String(StringLen::N(255))),
make_col!("id", ColumnType::String(StringLen::None)),
make_col!(
"cake_id",
ColumnType::Custom(SeaRc::new(Alias::new("cus_col")))
Expand Down Expand Up @@ -493,8 +493,8 @@ mod tests {
fn test_get_def() {
let columns = setup();
let col_defs = vec![
"ColumnType::string(Some(255u32)).def()",
"ColumnType::string(None).def()",
"ColumnType::String(StringLen::N(255u32)).def()",
"ColumnType::String(StringLen::None).def()",
"ColumnType::custom(\"cus_col\").def()",
"ColumnType::TinyInteger.def()",
"ColumnType::TinyUnsigned.def()",
Expand Down Expand Up @@ -681,7 +681,7 @@ mod tests {
assert_eq!(
column.get_def().to_string(),
quote! {
ColumnType::string(None).def().null()
ColumnType::String(StringLen::None).def().null()
}
.to_string()
);
Expand Down
8 changes: 4 additions & 4 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ mod tests {
use pretty_assertions::assert_eq;
use proc_macro2::TokenStream;
use quote::quote;
use sea_query::{Alias, ColumnType, ForeignKeyAction, RcOrArc, SeaRc};
use sea_query::{Alias, ColumnType, ForeignKeyAction, RcOrArc, SeaRc, StringLen};
use std::io::{self, BufRead, BufReader, Read};

fn setup() -> Vec<Entity> {
Expand Down Expand Up @@ -993,7 +993,7 @@ mod tests {
},
Column {
name: "name".to_owned(),
col_type: ColumnType::string(Some(255)),
col_type: ColumnType::String(StringLen::N(255)),
auto_increment: false,
not_null: true,
unique: false,
Expand All @@ -1020,7 +1020,7 @@ mod tests {
},
Column {
name: "name".to_owned(),
col_type: ColumnType::string(Some(255)),
col_type: ColumnType::String(StringLen::N(255)),
auto_increment: false,
not_null: true,
unique: false,
Expand Down Expand Up @@ -1074,7 +1074,7 @@ mod tests {
},
Column {
name: "_name_".to_owned(),
col_type: ColumnType::string(Some(255)),
col_type: ColumnType::String(StringLen::N(255)),
auto_increment: false,
not_null: true,
unique: false,
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/tests/expanded/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(Some(255u32)).def(),
Self::Name => ColumnType::String(StringLen::N(255u32)).def(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/tests/expanded/fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(Some(255u32)).def(),
Self::Name => ColumnType::String(StringLen::N(255u32)).def(),
Self::CakeId => ColumnType::Integer.def().null(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/tests/expanded/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(Some(255u32)).def(),
Self::Name => ColumnType::String(StringLen::N(255u32)).def(),
Self::FruitId => ColumnType::Integer.def().null(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/tests/expanded_with_schema_name/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(Some(255u32)).def(),
Self::Name => ColumnType::String(StringLen::N(255u32)).def(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/tests/expanded_with_schema_name/fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(Some(255u32)).def(),
Self::Name => ColumnType::String(StringLen::N(255u32)).def(),
Self::CakeId => ColumnType::Integer.def().null(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/tests/expanded_with_schema_name/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::string(Some(255u32)).def(),
Self::Name => ColumnType::String(StringLen::N(255u32)).def(),
Self::FruitId => ColumnType::Integer.def().null(),
}
}
Expand Down
Loading

0 comments on commit 7ed40c1

Please sign in to comment.