Fixup
This commit is contained in:
parent
892c0fe57d
commit
d22ff0db5e
@ -23,7 +23,7 @@ pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
use common::features::byte_primary_key::*;
|
||||
|
||||
let model = Model {
|
||||
id: vec![1],
|
||||
id: vec![1, 2, 3],
|
||||
value: "First Row".to_owned(),
|
||||
};
|
||||
|
||||
@ -41,7 +41,7 @@ pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
};
|
||||
|
||||
let update_res = Entity::update(updated_active_model.clone())
|
||||
.filter(Column::Id.eq(vec![1, 4]))
|
||||
.filter(Column::Id.eq(vec![1, 2, 4]))
|
||||
.exec(db)
|
||||
.await;
|
||||
|
||||
@ -53,7 +53,7 @@ pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
);
|
||||
|
||||
let update_res = Entity::update(updated_active_model.clone())
|
||||
.filter(Column::Id.eq(vec![1]))
|
||||
.filter(Column::Id.eq(vec![1, 2, 3]))
|
||||
.exec(db)
|
||||
.await?;
|
||||
|
||||
@ -61,11 +61,11 @@ pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
|
||||
assert_eq!(
|
||||
Entity::find()
|
||||
.filter(Column::Id.eq(vec![1]))
|
||||
.filter(Column::Id.eq(vec![1, 2, 3]))
|
||||
.one(db)
|
||||
.await?,
|
||||
Some(Model {
|
||||
id: vec![1],
|
||||
id: vec![1, 2, 3],
|
||||
value: "First Row (Updated)".to_owned(),
|
||||
})
|
||||
);
|
||||
|
@ -1,8 +1,10 @@
|
||||
pub use super::super::bakery_chain::*;
|
||||
|
||||
use super::*;
|
||||
use crate::common::setup::create_table;
|
||||
use sea_orm::{error::*, sea_query, DatabaseConnection, DbConn, ExecResult};
|
||||
use crate::common::setup::{create_table, create_table_without_asserts};
|
||||
use sea_orm::{
|
||||
error::*, sea_query, ConnectionTrait, DatabaseConnection, DbBackend, DbConn, ExecResult,
|
||||
};
|
||||
use sea_query::{ColumnDef, ForeignKeyCreateStatement};
|
||||
|
||||
pub async fn create_tables(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
@ -103,14 +105,15 @@ pub async fn create_self_join_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
}
|
||||
|
||||
pub async fn create_byte_primary_key_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
let mut primary_key_col = ColumnDef::new(byte_primary_key::Column::Id);
|
||||
match db.get_database_backend() {
|
||||
DbBackend::MySql => primary_key_col.binary_len(3),
|
||||
DbBackend::Sqlite | DbBackend::Postgres => primary_key_col.binary(),
|
||||
};
|
||||
|
||||
let stmt = sea_query::Table::create()
|
||||
.table(byte_primary_key::Entity)
|
||||
.col(
|
||||
ColumnDef::new(byte_primary_key::Column::Id)
|
||||
.binary()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(primary_key_col.not_null().primary_key())
|
||||
.col(
|
||||
ColumnDef::new(byte_primary_key::Column::Value)
|
||||
.string()
|
||||
@ -118,5 +121,5 @@ pub async fn create_byte_primary_key_table(db: &DbConn) -> Result<ExecResult, Db
|
||||
)
|
||||
.to_owned();
|
||||
|
||||
create_table(db, &stmt, BytePrimaryKey).await
|
||||
create_table_without_asserts(db, &stmt).await
|
||||
}
|
||||
|
@ -82,6 +82,19 @@ pub async fn create_table<E>(
|
||||
where
|
||||
E: EntityTrait,
|
||||
{
|
||||
let builder = db.get_database_backend();
|
||||
assert_eq!(
|
||||
builder.build(&Schema::create_table_from_entity(entity)),
|
||||
builder.build(create)
|
||||
);
|
||||
|
||||
create_table_without_asserts(db, create).await
|
||||
}
|
||||
|
||||
pub async fn create_table_without_asserts(
|
||||
db: &DbConn,
|
||||
create: &TableCreateStatement,
|
||||
) -> Result<ExecResult, DbErr> {
|
||||
let builder = db.get_database_backend();
|
||||
if builder != DbBackend::Sqlite {
|
||||
let stmt = builder.build(
|
||||
@ -92,11 +105,5 @@ where
|
||||
);
|
||||
db.execute(stmt).await?;
|
||||
}
|
||||
|
||||
let stmt = builder.build(create);
|
||||
assert_eq!(
|
||||
builder.build(&Schema::create_table_from_entity(entity)),
|
||||
stmt
|
||||
);
|
||||
db.execute(stmt).await
|
||||
db.execute(builder.build(create)).await
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user