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