commit
b32fe669fa
@ -31,7 +31,7 @@ chrono = { version = "^0", optional = true }
|
|||||||
futures = { version = "^0.3" }
|
futures = { version = "^0.3" }
|
||||||
futures-util = { version = "^0.3" }
|
futures-util = { version = "^0.3" }
|
||||||
rust_decimal = { version = "^1", optional = true }
|
rust_decimal = { version = "^1", optional = true }
|
||||||
sea-orm-macros = { version = "^0.1.1", optional = true }
|
sea-orm-macros = { version = "^0.1.1", path = "sea-orm-macros", optional = true }
|
||||||
sea-query = { version = "^0.16", features = ["thread-safe"] }
|
sea-query = { version = "^0.16", features = ["thread-safe"] }
|
||||||
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
||||||
serde = { version = "^1.0", features = ["derive"] }
|
serde = { version = "^1.0", features = ["derive"] }
|
||||||
@ -40,6 +40,7 @@ sqlx-core = { version = "^0.5", optional = true }
|
|||||||
sqlx-macros = { version = "^0.5", optional = true }
|
sqlx-macros = { version = "^0.5", optional = true }
|
||||||
serde_json = { version = "^1", optional = true }
|
serde_json = { version = "^1", optional = true }
|
||||||
uuid = { version = "0.8", features = ["serde", "v4"], optional = true }
|
uuid = { version = "0.8", features = ["serde", "v4"], optional = true }
|
||||||
|
log = { version = "^0.4", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
smol = { version = "^1.2" }
|
smol = { version = "^1.2" }
|
||||||
@ -49,11 +50,12 @@ tokio = { version = "^1.6", features = ["full"] }
|
|||||||
actix-rt = { version = "2.2.0" }
|
actix-rt = { version = "2.2.0" }
|
||||||
maplit = { version = "^1" }
|
maplit = { version = "^1" }
|
||||||
rust_decimal_macros = { version = "^1" }
|
rust_decimal_macros = { version = "^1" }
|
||||||
|
env_logger = { version = "^0.9" }
|
||||||
sea-orm = { path = ".", features = ["debug-print"] }
|
sea-orm = { path = ".", features = ["debug-print"] }
|
||||||
pretty_assertions = { version = "^0.7" }
|
pretty_assertions = { version = "^0.7" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
debug-print = []
|
debug-print = ["log"]
|
||||||
default = [
|
default = [
|
||||||
"macros",
|
"macros",
|
||||||
"mock",
|
"mock",
|
||||||
|
@ -99,6 +99,10 @@ pub fn test(_: TokenStream, input: TokenStream) -> TokenStream {
|
|||||||
#[test]
|
#[test]
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
fn #name() #ret {
|
fn #name() #ret {
|
||||||
|
let _ = ::env_logger::builder()
|
||||||
|
.filter_level(::log::LevelFilter::Debug)
|
||||||
|
.is_test(true)
|
||||||
|
.try_init();
|
||||||
crate::block_on!(async { #body })
|
crate::block_on!(async { #body })
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -2,19 +2,22 @@ use crate::{
|
|||||||
debug_print, error::*, DatabaseConnection, DbBackend, ExecResult, MockDatabase, QueryResult,
|
debug_print, error::*, DatabaseConnection, DbBackend, ExecResult, MockDatabase, QueryResult,
|
||||||
Statement, Transaction,
|
Statement, Transaction,
|
||||||
};
|
};
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Mutex,
|
Mutex,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct MockDatabaseConnector;
|
pub struct MockDatabaseConnector;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct MockDatabaseConnection {
|
pub struct MockDatabaseConnection {
|
||||||
counter: AtomicUsize,
|
counter: AtomicUsize,
|
||||||
mocker: Mutex<Box<dyn MockDatabaseTrait>>,
|
mocker: Mutex<Box<dyn MockDatabaseTrait>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MockDatabaseTrait: Send {
|
pub trait MockDatabaseTrait: Send + Debug {
|
||||||
fn execute(&mut self, counter: usize, stmt: Statement) -> Result<ExecResult, DbErr>;
|
fn execute(&mut self, counter: usize, stmt: Statement) -> Result<ExecResult, DbErr>;
|
||||||
|
|
||||||
fn query(&mut self, counter: usize, stmt: Statement) -> Result<Vec<QueryResult>, DbErr>;
|
fn query(&mut self, counter: usize, stmt: Statement) -> Result<Vec<QueryResult>, DbErr>;
|
||||||
|
@ -10,8 +10,10 @@ use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement};
|
|||||||
|
|
||||||
use super::sqlx_common::*;
|
use super::sqlx_common::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SqlxMySqlConnector;
|
pub struct SqlxMySqlConnector;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SqlxMySqlPoolConnection {
|
pub struct SqlxMySqlPoolConnection {
|
||||||
pool: MySqlPool,
|
pool: MySqlPool,
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,10 @@ use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement};
|
|||||||
|
|
||||||
use super::sqlx_common::*;
|
use super::sqlx_common::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SqlxPostgresConnector;
|
pub struct SqlxPostgresConnector;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SqlxPostgresPoolConnection {
|
pub struct SqlxPostgresPoolConnection {
|
||||||
pool: PgPool,
|
pool: PgPool,
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,10 @@ use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement};
|
|||||||
|
|
||||||
use super::sqlx_common::*;
|
use super::sqlx_common::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SqlxSqliteConnector;
|
pub struct SqlxSqliteConnector;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SqlxSqlitePoolConnection {
|
pub struct SqlxSqlitePoolConnection {
|
||||||
pool: SqlitePool,
|
pool: SqlitePool,
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ pub trait Linked {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RelationDef {
|
pub struct RelationDef {
|
||||||
pub rel_type: RelationType,
|
pub rel_type: RelationType,
|
||||||
pub from_tbl: TableRef,
|
pub from_tbl: TableRef,
|
||||||
@ -57,6 +58,7 @@ pub struct RelationDef {
|
|||||||
pub on_update: Option<ForeignKeyAction>,
|
pub on_update: Option<ForeignKeyAction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RelationBuilder<E, R>
|
pub struct RelationBuilder<E, R>
|
||||||
where
|
where
|
||||||
E: EntityTrait,
|
E: EntityTrait,
|
||||||
|
@ -21,10 +21,10 @@ where
|
|||||||
column_def.unique_key();
|
column_def.unique_key();
|
||||||
}
|
}
|
||||||
for primary_key in E::PrimaryKey::iter() {
|
for primary_key in E::PrimaryKey::iter() {
|
||||||
if column.to_string() == primary_key.into_column().to_string()
|
if column.to_string() == primary_key.into_column().to_string() {
|
||||||
&& E::PrimaryKey::auto_increment()
|
if E::PrimaryKey::auto_increment() {
|
||||||
{
|
column_def.auto_increment();
|
||||||
column_def.auto_increment();
|
}
|
||||||
if E::PrimaryKey::iter().count() == 1 {
|
if E::PrimaryKey::iter().count() == 1 {
|
||||||
column_def.primary_key();
|
column_def.primary_key();
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ pub trait TryGetable: Sized {
|
|||||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError>;
|
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum TryGetError {
|
pub enum TryGetError {
|
||||||
DbErr(DbErr),
|
DbErr(DbErr),
|
||||||
Null,
|
Null,
|
||||||
|
@ -30,6 +30,7 @@ pub trait SelectorTrait {
|
|||||||
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, DbErr>;
|
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, DbErr>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SelectModel<M>
|
pub struct SelectModel<M>
|
||||||
where
|
where
|
||||||
M: FromQueryResult,
|
M: FromQueryResult,
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
#![deny(
|
||||||
|
missing_debug_implementations,
|
||||||
|
clippy::print_stderr,
|
||||||
|
clippy::print_stdout
|
||||||
|
)]
|
||||||
|
|
||||||
//! <div align="center">
|
//! <div align="center">
|
||||||
//!
|
//!
|
||||||
//! <img src="https://www.sea-ql.org/SeaORM/img/SeaORM banner.png"/>
|
//! <img src="https://www.sea-ql.org/SeaORM/img/SeaORM banner.png"/>
|
||||||
|
@ -75,6 +75,7 @@ impl Related<super::filling::Entity> for Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CakeToFilling;
|
pub struct CakeToFilling;
|
||||||
|
|
||||||
impl Linked for CakeToFilling {
|
impl Linked for CakeToFilling {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[cfg(feature = "debug-print")]
|
#[cfg(feature = "debug-print")]
|
||||||
macro_rules! debug_print {
|
macro_rules! debug_print {
|
||||||
($( $args:expr ),*) => { println!( $( $args ),* ); }
|
($( $args:expr ),*) => { log::debug!( $( $args ),* ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -286,5 +286,5 @@ pub async fn create_metadata_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
.col(ColumnDef::new(metadata::Column::Value).string().not_null())
|
.col(ColumnDef::new(metadata::Column::Value).string().not_null())
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
create_table(db, &stmt).await
|
create_table(db, &stmt, Metadata).await
|
||||||
}
|
}
|
||||||
|
@ -494,7 +494,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
profit_margin: Set(10.4),
|
profit_margin: Set(10.4),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let seaside_bakery_res: InsertResult = Bakery::insert(seaside_bakery).exec(&ctx.db).await?;
|
let seaside_bakery_res = Bakery::insert(seaside_bakery).exec(&ctx.db).await?;
|
||||||
|
|
||||||
// Bob's Baker, Cake & Cake Baker
|
// Bob's Baker, Cake & Cake Baker
|
||||||
let baker_bob = baker::ActiveModel {
|
let baker_bob = baker::ActiveModel {
|
||||||
@ -507,7 +507,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let baker_bob_res: InsertResult = Baker::insert(baker_bob).exec(&ctx.db).await?;
|
let baker_bob_res = Baker::insert(baker_bob).exec(&ctx.db).await?;
|
||||||
let mud_cake = cake::ActiveModel {
|
let mud_cake = cake::ActiveModel {
|
||||||
name: Set("Mud Cake".to_owned()),
|
name: Set("Mud Cake".to_owned()),
|
||||||
price: Set(dec!(10.25)),
|
price: Set(dec!(10.25)),
|
||||||
@ -516,7 +516,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let mud_cake_res: InsertResult = Cake::insert(mud_cake).exec(&ctx.db).await?;
|
let mud_cake_res = Cake::insert(mud_cake).exec(&ctx.db).await?;
|
||||||
let bob_cakes_bakers = cakes_bakers::ActiveModel {
|
let bob_cakes_bakers = cakes_bakers::ActiveModel {
|
||||||
cake_id: Set(mud_cake_res.last_insert_id as i32),
|
cake_id: Set(mud_cake_res.last_insert_id as i32),
|
||||||
baker_id: Set(baker_bob_res.last_insert_id as i32),
|
baker_id: Set(baker_bob_res.last_insert_id as i32),
|
||||||
@ -533,7 +533,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let baker_bobby_res: InsertResult = Baker::insert(baker_bobby).exec(&ctx.db).await?;
|
let baker_bobby_res = Baker::insert(baker_bobby).exec(&ctx.db).await?;
|
||||||
let cheese_cake = cake::ActiveModel {
|
let cheese_cake = cake::ActiveModel {
|
||||||
name: Set("Cheese Cake".to_owned()),
|
name: Set("Cheese Cake".to_owned()),
|
||||||
price: Set(dec!(20.5)),
|
price: Set(dec!(20.5)),
|
||||||
@ -542,7 +542,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let cheese_cake_res: InsertResult = Cake::insert(cheese_cake).exec(&ctx.db).await?;
|
let cheese_cake_res = Cake::insert(cheese_cake).exec(&ctx.db).await?;
|
||||||
let bobby_cakes_bakers = cakes_bakers::ActiveModel {
|
let bobby_cakes_bakers = cakes_bakers::ActiveModel {
|
||||||
cake_id: Set(cheese_cake_res.last_insert_id as i32),
|
cake_id: Set(cheese_cake_res.last_insert_id as i32),
|
||||||
baker_id: Set(baker_bobby_res.last_insert_id as i32),
|
baker_id: Set(baker_bobby_res.last_insert_id as i32),
|
||||||
@ -559,7 +559,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let chocolate_cake_res: InsertResult = Cake::insert(chocolate_cake).exec(&ctx.db).await?;
|
let chocolate_cake_res = Cake::insert(chocolate_cake).exec(&ctx.db).await?;
|
||||||
let bobby_cakes_bakers = cakes_bakers::ActiveModel {
|
let bobby_cakes_bakers = cakes_bakers::ActiveModel {
|
||||||
cake_id: Set(chocolate_cake_res.last_insert_id as i32),
|
cake_id: Set(chocolate_cake_res.last_insert_id as i32),
|
||||||
baker_id: Set(baker_bobby_res.last_insert_id as i32),
|
baker_id: Set(baker_bobby_res.last_insert_id as i32),
|
||||||
@ -575,7 +575,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
notes: Set(Some("Loves cheese cake".to_owned())),
|
notes: Set(Some("Loves cheese cake".to_owned())),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let customer_kate_res: InsertResult = Customer::insert(customer_kate).exec(&ctx.db).await?;
|
let customer_kate_res = Customer::insert(customer_kate).exec(&ctx.db).await?;
|
||||||
let kate_order_1 = order::ActiveModel {
|
let kate_order_1 = order::ActiveModel {
|
||||||
bakery_id: Set(seaside_bakery_res.last_insert_id as i32),
|
bakery_id: Set(seaside_bakery_res.last_insert_id as i32),
|
||||||
customer_id: Set(customer_kate_res.last_insert_id as i32),
|
customer_id: Set(customer_kate_res.last_insert_id as i32),
|
||||||
@ -583,7 +583,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
placed_at: Set(Utc::now().naive_utc()),
|
placed_at: Set(Utc::now().naive_utc()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let kate_order_1_res: InsertResult = Order::insert(kate_order_1).exec(&ctx.db).await?;
|
let kate_order_1_res = Order::insert(kate_order_1).exec(&ctx.db).await?;
|
||||||
lineitem::ActiveModel {
|
lineitem::ActiveModel {
|
||||||
cake_id: Set(cheese_cake_res.last_insert_id as i32),
|
cake_id: Set(cheese_cake_res.last_insert_id as i32),
|
||||||
order_id: Set(kate_order_1_res.last_insert_id as i32),
|
order_id: Set(kate_order_1_res.last_insert_id as i32),
|
||||||
@ -600,7 +600,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
placed_at: Set(Utc::now().naive_utc()),
|
placed_at: Set(Utc::now().naive_utc()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let kate_order_2_res: InsertResult = Order::insert(kate_order_2).exec(&ctx.db).await?;
|
let kate_order_2_res = Order::insert(kate_order_2).exec(&ctx.db).await?;
|
||||||
lineitem::ActiveModel {
|
lineitem::ActiveModel {
|
||||||
cake_id: Set(chocolate_cake_res.last_insert_id as i32),
|
cake_id: Set(chocolate_cake_res.last_insert_id as i32),
|
||||||
order_id: Set(kate_order_2_res.last_insert_id as i32),
|
order_id: Set(kate_order_2_res.last_insert_id as i32),
|
||||||
@ -617,7 +617,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
notes: Set(Some("Loves all cakes".to_owned())),
|
notes: Set(Some("Loves all cakes".to_owned())),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let customer_kara_res: InsertResult = Customer::insert(customer_kara).exec(&ctx.db).await?;
|
let customer_kara_res = Customer::insert(customer_kara).exec(&ctx.db).await?;
|
||||||
let kara_order_1 = order::ActiveModel {
|
let kara_order_1 = order::ActiveModel {
|
||||||
bakery_id: Set(seaside_bakery_res.last_insert_id as i32),
|
bakery_id: Set(seaside_bakery_res.last_insert_id as i32),
|
||||||
customer_id: Set(customer_kara_res.last_insert_id as i32),
|
customer_id: Set(customer_kara_res.last_insert_id as i32),
|
||||||
@ -625,7 +625,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
placed_at: Set(Utc::now().naive_utc()),
|
placed_at: Set(Utc::now().naive_utc()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let kara_order_1_res: InsertResult = Order::insert(kara_order_1).exec(&ctx.db).await?;
|
let kara_order_1_res = Order::insert(kara_order_1).exec(&ctx.db).await?;
|
||||||
lineitem::ActiveModel {
|
lineitem::ActiveModel {
|
||||||
cake_id: Set(mud_cake_res.last_insert_id as i32),
|
cake_id: Set(mud_cake_res.last_insert_id as i32),
|
||||||
order_id: Set(kara_order_1_res.last_insert_id as i32),
|
order_id: Set(kara_order_1_res.last_insert_id as i32),
|
||||||
@ -642,7 +642,7 @@ pub async fn linked() -> Result<(), DbErr> {
|
|||||||
placed_at: Set(Utc::now().naive_utc()),
|
placed_at: Set(Utc::now().naive_utc()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let kara_order_2_res: InsertResult = Order::insert(kara_order_2).exec(&ctx.db).await?;
|
let kara_order_2_res = Order::insert(kara_order_2).exec(&ctx.db).await?;
|
||||||
lineitem::ActiveModel {
|
lineitem::ActiveModel {
|
||||||
cake_id: Set(cheese_cake_res.last_insert_id as i32),
|
cake_id: Set(cheese_cake_res.last_insert_id as i32),
|
||||||
order_id: Set(kara_order_2_res.last_insert_id as i32),
|
order_id: Set(kara_order_2_res.last_insert_id as i32),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user