First unit test
This commit is contained in:
parent
6ffed93b46
commit
9080d16c24
16
Cargo.toml
16
Cargo.toml
@ -22,10 +22,22 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "^0.1"
|
async-trait = "^0.1"
|
||||||
async-std = { version = "^1.9", features = [ "attributes" ] }
|
|
||||||
futures = { version = "^0.3" }
|
futures = { version = "^0.3" }
|
||||||
sea-query = { path = "../sea-query", version = "^0.10", features = [ "sqlx-mysql" ] }
|
sea-query = { path = "../sea-query", version = "^0.10", features = [ "sqlx-mysql" ] }
|
||||||
# sea-schema = { path = "../sea-schema" }
|
# sea-schema = { path = "../sea-schema" }
|
||||||
serde = { version = "^1.0", features = [ "derive" ] }
|
serde = { version = "^1.0", features = [ "derive" ] }
|
||||||
sqlx = { version = "^0.5", features = [ "runtime-async-std-native-tls", "mysql", "any", "chrono", "time", "bigdecimal", "decimal", "uuid", "json" ] }
|
sqlx = { version = "^0.5", optional = true }
|
||||||
strum = { version = "^0.20", features = [ "derive" ] }
|
strum = { version = "^0.20", features = [ "derive" ] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
debug-print = []
|
||||||
|
default = [ "sqlx-mysql", "runtime-async-std-native-tls" ]
|
||||||
|
sqlx-dep = [ "sqlx" ]
|
||||||
|
sqlx-mysql = [ "sqlx-dep", "sea-query/sqlx-mysql", "sqlx/mysql" ]
|
||||||
|
sqlx-postgres = [ "sqlx-dep", "sea-query/sqlx-postgres", "sqlx/postgres" ]
|
||||||
|
runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls" ]
|
||||||
|
runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls" ]
|
||||||
|
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls" ]
|
||||||
|
runtime-actix-rustls = [ "sqlx/runtime-actix-rustls" ]
|
||||||
|
runtime-async-std-rustls = [ "sqlx/runtime-async-std-rustls" ]
|
||||||
|
runtime-tokio-rustls = [ "sqlx/runtime-tokio-rustls" ]
|
||||||
|
@ -41,8 +41,11 @@ impl From<(String, Values)> for Statement {
|
|||||||
|
|
||||||
impl fmt::Display for Statement {
|
impl fmt::Display for Statement {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let builder = MySqlQueryBuilder::default();
|
let string = inject_parameters(
|
||||||
let string = inject_parameters(&self.sql, self.values.0.clone(), &builder);
|
&self.sql,
|
||||||
|
self.values.0.clone(),
|
||||||
|
&MySqlQueryBuilder::default(),
|
||||||
|
);
|
||||||
write!(f, "{}", &string)
|
write!(f, "{}", &string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ mod database;
|
|||||||
mod driver;
|
mod driver;
|
||||||
mod entity;
|
mod entity;
|
||||||
mod query;
|
mod query;
|
||||||
|
pub(crate) mod tests_cfg;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
pub use connector::*;
|
pub use connector::*;
|
||||||
|
@ -87,3 +87,20 @@ where
|
|||||||
self.as_query().build(builder).into()
|
self.as_query().build(builder).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::tests_cfg::cake;
|
||||||
|
use crate::Entity;
|
||||||
|
use sea_query::MySqlQueryBuilder;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_1() {
|
||||||
|
assert_eq!(
|
||||||
|
cake::Cake::find()
|
||||||
|
.build(MySqlQueryBuilder::default())
|
||||||
|
.to_string(),
|
||||||
|
"SELECT `cake`.`id`, `cake`.`name` FROM `cake`"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
48
src/tests_cfg/cake.rs
Normal file
48
src/tests_cfg/cake.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
use crate::{Column, ColumnType, Entity, Identity, IntoIdentity, Relation, RelationDef};
|
||||||
|
use sea_query::Iden;
|
||||||
|
use strum::EnumIter;
|
||||||
|
|
||||||
|
#[derive(Iden, Default, Debug)]
|
||||||
|
pub struct Cake;
|
||||||
|
|
||||||
|
#[derive(Iden, EnumIter)]
|
||||||
|
pub enum CakeColumn {
|
||||||
|
Id,
|
||||||
|
Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(EnumIter)]
|
||||||
|
pub enum CakeRelation {}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, PartialEq)]
|
||||||
|
pub struct CakeModel {
|
||||||
|
pub id: Option<i32>,
|
||||||
|
pub name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for Cake {
|
||||||
|
type Model = CakeModel;
|
||||||
|
|
||||||
|
type Column = CakeColumn;
|
||||||
|
|
||||||
|
type Relation = CakeRelation;
|
||||||
|
|
||||||
|
fn primary_key() -> Identity {
|
||||||
|
CakeColumn::Id.into_identity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Column for CakeColumn {
|
||||||
|
fn col_type(&self) -> ColumnType {
|
||||||
|
match self {
|
||||||
|
Self::Id => ColumnType::Integer(None),
|
||||||
|
Self::Name => ColumnType::String(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Relation for CakeRelation {
|
||||||
|
fn rel_def(&self) -> RelationDef {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
1
src/tests_cfg/mod.rs
Normal file
1
src/tests_cfg/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod cake;
|
Loading…
x
Reference in New Issue
Block a user