commit
f4f21b439e
18
.github/workflows/rust.yml
vendored
18
.github/workflows/rust.yml
vendored
@ -11,6 +11,24 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Clippy
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
components: clippy
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- uses: actions-rs/clippy-check@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
args: --all-targets --all
|
||||||
|
|
||||||
compile-sqlite:
|
compile-sqlite:
|
||||||
name: Compile SQLite
|
name: Compile SQLite
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
@ -119,33 +119,18 @@ impl From<&ColumnDef> for Column {
|
|||||||
Some(ty) => ty.clone(),
|
Some(ty) => ty.clone(),
|
||||||
None => panic!("ColumnType should not be empty"),
|
None => panic!("ColumnType should not be empty"),
|
||||||
};
|
};
|
||||||
let auto_increments: Vec<bool> = col_def
|
let auto_increment = col_def
|
||||||
.get_column_spec()
|
.get_column_spec()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|spec| match spec {
|
.any(|spec| matches!(spec, ColumnSpec::AutoIncrement));
|
||||||
ColumnSpec::AutoIncrement => Some(true),
|
let not_null = col_def
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let auto_increment = !auto_increments.is_empty();
|
|
||||||
let not_nulls: Vec<bool> = col_def
|
|
||||||
.get_column_spec()
|
.get_column_spec()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|spec| match spec {
|
.any(|spec| matches!(spec, ColumnSpec::NotNull));
|
||||||
ColumnSpec::NotNull => Some(true),
|
let unique = col_def
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let not_null = !not_nulls.is_empty();
|
|
||||||
let uniques: Vec<bool> = col_def
|
|
||||||
.get_column_spec()
|
.get_column_spec()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|spec| match spec {
|
.any(|spec| matches!(spec, ColumnSpec::UniqueKey));
|
||||||
ColumnSpec::UniqueKey => Some(true),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let unique = !uniques.is_empty();
|
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
col_type,
|
col_type,
|
||||||
|
@ -34,11 +34,6 @@ impl EntityTransformer {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|col_def| col_def.into())
|
.map(|col_def| col_def.into())
|
||||||
.collect();
|
.collect();
|
||||||
let unique_columns: Vec<String> = columns
|
|
||||||
.iter()
|
|
||||||
.filter(|col| col.unique)
|
|
||||||
.map(|col| col.name.clone())
|
|
||||||
.collect();
|
|
||||||
let relations = table_create
|
let relations = table_create
|
||||||
.get_foreign_key_create_stmts()
|
.get_foreign_key_create_stmts()
|
||||||
.iter()
|
.iter()
|
||||||
@ -85,8 +80,13 @@ impl EntityTransformer {
|
|||||||
false => {
|
false => {
|
||||||
let ref_table = rel.ref_table;
|
let ref_table = rel.ref_table;
|
||||||
let mut unique = true;
|
let mut unique = true;
|
||||||
for col in rel.columns.iter() {
|
for column in rel.columns.iter() {
|
||||||
if !unique_columns.contains(col) {
|
if !entity
|
||||||
|
.columns
|
||||||
|
.iter()
|
||||||
|
.filter(|col| col.unique)
|
||||||
|
.any(|col| col.name.as_str() == column)
|
||||||
|
{
|
||||||
unique = false;
|
unique = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ mod tests {
|
|||||||
use sea_query::ColumnType;
|
use sea_query::ColumnType;
|
||||||
use std::io::{self, BufRead, BufReader};
|
use std::io::{self, BufRead, BufReader};
|
||||||
|
|
||||||
const ENTITY_FILES: [&'static str; 5] = [
|
const ENTITY_FILES: [&str; 5] = [
|
||||||
include_str!("../../tests/entity/cake.rs"),
|
include_str!("../../tests/entity/cake.rs"),
|
||||||
include_str!("../../tests/entity/cake_filling.rs"),
|
include_str!("../../tests/entity/cake_filling.rs"),
|
||||||
include_str!("../../tests/entity/filling.rs"),
|
include_str!("../../tests/entity/filling.rs"),
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
pub use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, Database, DbConn};
|
||||||
use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, Database, DbConn};
|
|
||||||
|
|
||||||
// DATABASE_URL="sqlite::memory:" cargo test --features sqlx-sqlit,runtime-async-std --test basic
|
// DATABASE_URL="sqlite::memory:" cargo test --features sqlx-sqlit,runtime-async-std --test basic
|
||||||
#[sea_orm_macros::test]
|
#[sea_orm_macros::test]
|
||||||
|
@ -19,7 +19,7 @@ impl TestContext {
|
|||||||
let db: DatabaseConnection = setup::setup(&base_url, test_name).await;
|
let db: DatabaseConnection = setup::setup(&base_url, test_name).await;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
base_url: base_url,
|
base_url,
|
||||||
db_name: test_name.to_string(),
|
db_name: test_name.to_string(),
|
||||||
db,
|
db,
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
|
pub use super::super::bakery_chain::*;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
entity_to_table_create_statement, error::*, sea_query, DbConn, EntityTrait, ExecResult,
|
entity_to_table_create_statement, error::*, sea_query, DbConn, EntityTrait, ExecResult,
|
||||||
};
|
};
|
||||||
use sea_query::{ColumnDef, ForeignKey, ForeignKeyAction, Index, Table, TableCreateStatement};
|
use sea_query::{ColumnDef, ForeignKey, ForeignKeyAction, Index, Table, TableCreateStatement};
|
||||||
|
|
||||||
pub use super::super::bakery_chain::*;
|
|
||||||
|
|
||||||
async fn create_table<E>(
|
async fn create_table<E>(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
stmt: &TableCreateStatement,
|
stmt: &TableCreateStatement,
|
||||||
|
@ -51,7 +51,6 @@ pub async fn test_create_cake(db: &DbConn) {
|
|||||||
let cake_baker = cakes_bakers::ActiveModel {
|
let cake_baker = cakes_bakers::ActiveModel {
|
||||||
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
||||||
baker_id: Set(baker_insert_res.last_insert_id as i32),
|
baker_id: Set(baker_insert_res.last_insert_id as i32),
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
||||||
.exec(db)
|
.exec(db)
|
||||||
@ -70,7 +69,7 @@ pub async fn test_create_cake(db: &DbConn) {
|
|||||||
let cake_model = cake.unwrap();
|
let cake_model = cake.unwrap();
|
||||||
assert_eq!(cake_model.name, "Mud Cake");
|
assert_eq!(cake_model.name, "Mud Cake");
|
||||||
assert_eq!(cake_model.price, dec!(10.25));
|
assert_eq!(cake_model.price, dec!(10.25));
|
||||||
assert_eq!(cake_model.gluten_free, false);
|
assert!(!cake_model.gluten_free);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cake_model
|
cake_model
|
||||||
.find_related(Bakery)
|
.find_related(Bakery)
|
||||||
|
@ -50,7 +50,6 @@ pub async fn test_create_lineitem(db: &DbConn) {
|
|||||||
let cake_baker = cakes_bakers::ActiveModel {
|
let cake_baker = cakes_bakers::ActiveModel {
|
||||||
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
||||||
baker_id: Set(baker_insert_res.last_insert_id as i32),
|
baker_id: Set(baker_insert_res.last_insert_id as i32),
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
||||||
.exec(db)
|
.exec(db)
|
||||||
|
@ -50,7 +50,6 @@ pub async fn test_create_order(db: &DbConn) {
|
|||||||
let cake_baker = cakes_bakers::ActiveModel {
|
let cake_baker = cakes_bakers::ActiveModel {
|
||||||
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
||||||
baker_id: Set(baker_insert_res.last_insert_id as i32),
|
baker_id: Set(baker_insert_res.last_insert_id as i32),
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
||||||
.exec(db)
|
.exec(db)
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
use sea_orm::{entity::*, DbConn};
|
|
||||||
|
|
||||||
pub use super::common::bakery_chain::*;
|
|
||||||
|
|
||||||
pub mod create_baker;
|
pub mod create_baker;
|
||||||
pub mod create_cake;
|
pub mod create_cake;
|
||||||
pub mod create_lineitem;
|
pub mod create_lineitem;
|
||||||
@ -9,6 +5,16 @@ pub mod create_order;
|
|||||||
pub mod deletes;
|
pub mod deletes;
|
||||||
pub mod updates;
|
pub mod updates;
|
||||||
|
|
||||||
|
pub use create_baker::*;
|
||||||
|
pub use create_cake::*;
|
||||||
|
pub use create_lineitem::*;
|
||||||
|
pub use create_order::*;
|
||||||
|
pub use deletes::*;
|
||||||
|
pub use updates::*;
|
||||||
|
|
||||||
|
pub use super::common::bakery_chain::*;
|
||||||
|
use sea_orm::{entity::*, DbConn};
|
||||||
|
|
||||||
pub async fn test_create_bakery(db: &DbConn) {
|
pub async fn test_create_bakery(db: &DbConn) {
|
||||||
let seaside_bakery = bakery::ActiveModel {
|
let seaside_bakery = bakery::ActiveModel {
|
||||||
name: Set("SeaSide Bakery".to_owned()),
|
name: Set("SeaSide Bakery".to_owned()),
|
||||||
@ -28,7 +34,7 @@ pub async fn test_create_bakery(db: &DbConn) {
|
|||||||
assert!(bakery.is_some());
|
assert!(bakery.is_some());
|
||||||
let bakery_model = bakery.unwrap();
|
let bakery_model = bakery.unwrap();
|
||||||
assert_eq!(bakery_model.name, "SeaSide Bakery");
|
assert_eq!(bakery_model.name, "SeaSide Bakery");
|
||||||
assert_eq!(bakery_model.profit_margin, 10.4);
|
assert!((bakery_model.profit_margin - 10.4).abs() < f64::EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn test_create_customer(db: &DbConn) {
|
pub async fn test_create_customer(db: &DbConn) {
|
||||||
|
@ -36,7 +36,7 @@ pub async fn test_update_cake(db: &DbConn) {
|
|||||||
let cake_model = cake.unwrap();
|
let cake_model = cake.unwrap();
|
||||||
assert_eq!(cake_model.name, "Mud Cake");
|
assert_eq!(cake_model.name, "Mud Cake");
|
||||||
assert_eq!(cake_model.price, dec!(10.25));
|
assert_eq!(cake_model.price, dec!(10.25));
|
||||||
assert_eq!(cake_model.gluten_free, false);
|
assert!(!cake_model.gluten_free);
|
||||||
|
|
||||||
let mut cake_am: cake::ActiveModel = cake_model.into();
|
let mut cake_am: cake::ActiveModel = cake_model.into();
|
||||||
cake_am.name = Set("Extra chocolate mud cake".to_owned());
|
cake_am.name = Set("Extra chocolate mud cake".to_owned());
|
||||||
@ -75,7 +75,7 @@ pub async fn test_update_bakery(db: &DbConn) {
|
|||||||
assert!(bakery.is_some());
|
assert!(bakery.is_some());
|
||||||
let bakery_model = bakery.unwrap();
|
let bakery_model = bakery.unwrap();
|
||||||
assert_eq!(bakery_model.name, "SeaSide Bakery");
|
assert_eq!(bakery_model.name, "SeaSide Bakery");
|
||||||
assert_eq!(bakery_model.profit_margin, 10.4);
|
assert!((bakery_model.profit_margin - 10.40).abs() < f64::EPSILON);
|
||||||
|
|
||||||
let mut bakery_am: bakery::ActiveModel = bakery_model.into();
|
let mut bakery_am: bakery::ActiveModel = bakery_model.into();
|
||||||
bakery_am.name = Set("SeaBreeze Bakery".to_owned());
|
bakery_am.name = Set("SeaBreeze Bakery".to_owned());
|
||||||
@ -92,7 +92,7 @@ pub async fn test_update_bakery(db: &DbConn) {
|
|||||||
.expect("could not find bakery");
|
.expect("could not find bakery");
|
||||||
let bakery_model = bakery.unwrap();
|
let bakery_model = bakery.unwrap();
|
||||||
assert_eq!(bakery_model.name, "SeaBreeze Bakery");
|
assert_eq!(bakery_model.name, "SeaBreeze Bakery");
|
||||||
assert_eq!(bakery_model.profit_margin, 12.00);
|
assert!((bakery_model.profit_margin - 12.00).abs() < f64::EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn test_update_deleted_customer(db: &DbConn) {
|
pub async fn test_update_deleted_customer(db: &DbConn) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use sea_orm::DatabaseConnection;
|
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub use common::{bakery_chain::*, setup::*, TestContext};
|
|
||||||
|
|
||||||
mod crud;
|
mod crud;
|
||||||
|
|
||||||
|
pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||||
|
pub use crud::*;
|
||||||
|
use sea_orm::DatabaseConnection;
|
||||||
|
|
||||||
// Run the test locally:
|
// Run the test locally:
|
||||||
// DATABASE_URL="mysql://root:root@localhost" cargo test --features sqlx-mysql,runtime-async-std --test crud_tests
|
// DATABASE_URL="mysql://root:root@localhost" cargo test --features sqlx-mysql,runtime-async-std --test crud_tests
|
||||||
// DATABASE_URL="postgres://root:root@localhost" cargo test --features sqlx-postgres,runtime-async-std --test crud_tests
|
// DATABASE_URL="postgres://root:root@localhost" cargo test --features sqlx-postgres,runtime-async-std --test crud_tests
|
||||||
@ -20,18 +20,18 @@ async fn main() {
|
|||||||
ctx.delete().await;
|
ctx.delete().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_entities(db: &DatabaseConnection) {
|
pub async fn create_entities(db: &DatabaseConnection) {
|
||||||
crud::test_create_bakery(db).await;
|
test_create_bakery(db).await;
|
||||||
crud::create_baker::test_create_baker(db).await;
|
test_create_baker(db).await;
|
||||||
crud::test_create_customer(db).await;
|
test_create_customer(db).await;
|
||||||
crud::create_cake::test_create_cake(db).await;
|
test_create_cake(db).await;
|
||||||
crud::create_lineitem::test_create_lineitem(db).await;
|
test_create_lineitem(db).await;
|
||||||
crud::create_order::test_create_order(db).await;
|
test_create_order(db).await;
|
||||||
|
|
||||||
crud::updates::test_update_cake(db).await;
|
test_update_cake(db).await;
|
||||||
crud::updates::test_update_bakery(db).await;
|
test_update_bakery(db).await;
|
||||||
crud::updates::test_update_deleted_customer(db).await;
|
test_update_deleted_customer(db).await;
|
||||||
|
|
||||||
crud::deletes::test_delete_cake(db).await;
|
test_delete_cake(db).await;
|
||||||
crud::deletes::test_delete_bakery(db).await;
|
test_delete_bakery(db).await;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use sea_orm::{entity::prelude::*, DatabaseConnection, Set};
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
pub use common::{bakery_chain::*, setup::*, TestContext};
|
pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||||
|
use sea_orm::{entity::prelude::*, DatabaseConnection, Set};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[sea_orm_macros::test]
|
#[sea_orm_macros::test]
|
||||||
@ -19,7 +20,7 @@ async fn main() -> Result<(), DbErr> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_metadata(db: &DatabaseConnection) -> Result<(), DbErr> {
|
pub async fn create_metadata(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||||
let metadata = metadata::ActiveModel {
|
let metadata = metadata::ActiveModel {
|
||||||
uuid: Set(Uuid::new_v4()),
|
uuid: Set(Uuid::new_v4()),
|
||||||
key: Set("markup".to_owned()),
|
key: Set("markup".to_owned()),
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use sea_orm::entity::*;
|
|
||||||
use sea_orm::QueryFilter;
|
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
pub use common::{bakery_chain::*, setup::*, TestContext};
|
pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||||
|
pub use sea_orm::entity::*;
|
||||||
|
pub use sea_orm::QueryFilter;
|
||||||
|
|
||||||
// Run the test locally:
|
// Run the test locally:
|
||||||
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test query_tests
|
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test query_tests
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use chrono::offset::Utc;
|
|
||||||
use rust_decimal::prelude::*;
|
|
||||||
use rust_decimal_macros::dec;
|
|
||||||
use sea_orm::{entity::*, query::*, DbErr, FromQueryResult};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
|
pub use chrono::offset::Utc;
|
||||||
pub use common::{bakery_chain::*, setup::*, TestContext};
|
pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||||
|
pub use rust_decimal::prelude::*;
|
||||||
|
pub use rust_decimal_macros::dec;
|
||||||
|
pub use sea_orm::{entity::*, query::*, DbErr, FromQueryResult};
|
||||||
|
pub use uuid::Uuid;
|
||||||
|
|
||||||
// Run the test locally:
|
// Run the test locally:
|
||||||
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std-native-tls --test relational_tests
|
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std-native-tls --test relational_tests
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use chrono::offset::Utc;
|
|
||||||
use rust_decimal::prelude::*;
|
|
||||||
use rust_decimal_macros::dec;
|
|
||||||
use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
|
pub use chrono::offset::Utc;
|
||||||
pub use common::{bakery_chain::*, setup::*, TestContext};
|
pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||||
|
pub use rust_decimal::prelude::*;
|
||||||
|
pub use rust_decimal_macros::dec;
|
||||||
|
pub use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
|
||||||
|
pub use uuid::Uuid;
|
||||||
|
|
||||||
// Run the test locally:
|
// Run the test locally:
|
||||||
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests
|
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user