-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SeaQL:master' into master
- Loading branch information
Showing
15 changed files
with
331 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 | ||
//! | ||
//! This file tests that the JsonBinary column type is annotated correctly is | ||
//! compact entity form. More information can be found in this issue: | ||
//! | ||
//! https://github.com/SeaQL/sea-orm/issues/1344 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(table_name = "task")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub payload: Json, | ||
#[sea_orm(column_type = "JsonBinary")] | ||
pub payload_binary: Json, | ||
} | ||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation {} | ||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 | ||
//! | ||
//! This file tests that the JsonBinary column type is annotated correctly is | ||
//! expanded entity form. More information can be found in this issue: | ||
//! | ||
//! https://github.com/SeaQL/sea-orm/issues/1344 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)] | ||
pub struct Entity; | ||
impl EntityName for Entity { | ||
fn schema_name(&self) -> Option< &str > { | ||
Some("schema_name") | ||
} | ||
fn table_name(&self) -> &str { | ||
"task" | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq)] | ||
pub struct Model { | ||
pub id: i32, | ||
pub payload: Json, | ||
pub payload_binary: Json, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] | ||
pub enum Column { | ||
Id, | ||
Payload, | ||
PayloadBinary, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] | ||
pub enum PrimaryKey { | ||
Id, | ||
} | ||
|
||
impl PrimaryKeyTrait for PrimaryKey { | ||
type ValueType = i32; | ||
fn auto_increment() -> bool { | ||
true | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter)] | ||
pub enum Relation {} | ||
impl ColumnTrait for Column { | ||
type EntityName = Entity; | ||
fn def(&self) -> ColumnDef { | ||
match self { | ||
Self::Id => ColumnType::Integer.def(), | ||
// This is the part that is being tested. | ||
Self::Payload => ColumnType::Json.def(), | ||
Self::PayloadBinary => ColumnType::JsonBinary.def(), | ||
} | ||
} | ||
} | ||
impl RelationTrait for Relation { | ||
fn def(&self) -> RelationDef { | ||
panic!("No RelationDef") | ||
} | ||
} | ||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.