[issues] test case

This commit is contained in:
Chris Tsang 2023-01-18 19:23:29 +08:00
parent e5b69ebb73
commit f50dc1dd1c
3 changed files with 74 additions and 0 deletions

18
issues/1357/Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[workspace]
# A separate workspace
[package]
name = "sea-orm-issues-1357"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
anyhow = "1"
serde = "1"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
[dependencies.sea-orm]
path = "../../"
default-features = false
features = ["macros", "runtime-tokio-native-tls", "sqlx-sqlite"]

14
issues/1357/src/entity.rs Normal file
View File

@ -0,0 +1,14 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "pool")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

42
issues/1357/src/main.rs Normal file
View File

@ -0,0 +1,42 @@
use anyhow::Result;
use sea_orm::{ConnectionTrait, Database, EntityTrait, IntoActiveModel, Schema};
mod entity;
use entity::*;
#[tokio::main]
async fn main() -> Result<()> {
let db = Database::connect("sqlite::memory:").await.unwrap();
let builder = db.get_database_backend();
let schema = Schema::new(builder);
let stmt = schema.create_table_from_entity(Entity);
db.execute(builder.build(&stmt)).await?;
let model = Model {
id: 100,
name: "Hello".to_owned(),
};
let res = Entity::insert(model.clone().into_active_model())
.exec(&db)
.await?;
assert_eq!(Entity::find().one(&db).await?, Some(model.clone()));
assert_eq!(res.last_insert_id, model.id);
let model = Model {
id: -10,
name: "World".to_owned(),
};
let res = Entity::insert(model.clone().into_active_model())
.exec(&db)
.await?;
assert_eq!(Entity::find().one(&db).await?, Some(model.clone()));
assert_eq!(res.last_insert_id, model.id);
Ok(())
}