Refactor basic test
This commit is contained in:
parent
5930c4b278
commit
e7d2899019
@ -1,6 +1,5 @@
|
||||
use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, DbBackend, DbConn, Statement};
|
||||
|
||||
mod setup;
|
||||
#[allow(unused_imports)]
|
||||
use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, Database, DbConn};
|
||||
|
||||
// cargo test --test basic -- --nocapture
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
@ -8,13 +7,17 @@ mod setup;
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
async fn main() {
|
||||
let db: DbConn = setup::setup().await;
|
||||
use std::env;
|
||||
let base_url = env::var("DATABASE_URL").expect("Enviroment variable 'DATABASE_URL' not set");
|
||||
|
||||
let db: DbConn = Database::connect(&base_url).await.unwrap();
|
||||
|
||||
setup_schema(&db).await;
|
||||
|
||||
crud_cake(&db).await.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
async fn setup_schema(db: &DbConn) {
|
||||
use sea_query::*;
|
||||
|
||||
@ -28,14 +31,14 @@ async fn setup_schema(db: &DbConn) {
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(cake::Column::Name).string())
|
||||
.build(SqliteQueryBuilder);
|
||||
.to_owned();
|
||||
|
||||
let result = db
|
||||
.execute(Statement::from_string(DbBackend::Sqlite, stmt))
|
||||
.await;
|
||||
let builder = db.get_database_backend();
|
||||
let result = db.execute(builder.build(&stmt)).await;
|
||||
println!("Create table cake: {:?}", result);
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
async fn crud_cake(db: &DbConn) -> Result<(), DbErr> {
|
||||
let apple = cake::ActiveModel {
|
||||
name: Set("Apple Pie".to_owned()),
|
||||
|
@ -1,5 +0,0 @@
|
||||
use sea_orm::{Database, DatabaseConnection};
|
||||
|
||||
pub async fn setup() -> DatabaseConnection {
|
||||
Database::connect("sqlite::memory:").await.unwrap()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user