diff --git a/docs-site/content/docs/the-app/models.md b/docs-site/content/docs/the-app/models.md index b63fcf11..cd026a25 100644 --- a/docs-site/content/docs/the-app/models.md +++ b/docs-site/content/docs/the-app/models.md @@ -644,8 +644,8 @@ Integrate your seed into the app's Hook implementations by following these steps impl Hooks for App { // Other implementations... - async fn seed(db: &DatabaseConnection, base: &Path) -> Result<()> { - db::seed::(db, &base.join("users.yaml").display().to_string()).await?; + async fn seed(ctx: &AppContext, base: &Path) -> Result<()> { + db::seed::(&ctx.db, &base.join("users.yaml").display().to_string()).await?; Ok(()) } } diff --git a/loco-gen/src/templates/model/test.t b/loco-gen/src/templates/model/test.t index cd726899..6bf14346 100644 --- a/loco-gen/src/templates/model/test.t +++ b/loco-gen/src/templates/model/test.t @@ -26,7 +26,7 @@ async fn test_model() { configure_insta!(); let boot = boot_test::().await.unwrap(); - seed::(&boot.app_context.db).await.unwrap(); + seed::(&boot.app_context).await.unwrap(); // query your model, e.g.: // diff --git a/loco-gen/tests/templates/snapshots/generate[test_model]@Api_scaffold.snap b/loco-gen/tests/templates/snapshots/generate[test_model]@Api_scaffold.snap index e9c641f3..2b139301 100644 --- a/loco-gen/tests/templates/snapshots/generate[test_model]@Api_scaffold.snap +++ b/loco-gen/tests/templates/snapshots/generate[test_model]@Api_scaffold.snap @@ -20,7 +20,7 @@ async fn test_model() { configure_insta!(); let boot = boot_test::().await.unwrap(); - seed::(&boot.app_context.db).await.unwrap(); + seed::(&boot.app_context).await.unwrap(); // query your model, e.g.: // diff --git a/loco-gen/tests/templates/snapshots/generate[test_model]@Html_scaffold.snap b/loco-gen/tests/templates/snapshots/generate[test_model]@Html_scaffold.snap index e9c641f3..2b139301 100644 --- a/loco-gen/tests/templates/snapshots/generate[test_model]@Html_scaffold.snap +++ b/loco-gen/tests/templates/snapshots/generate[test_model]@Html_scaffold.snap @@ -20,7 +20,7 @@ async fn test_model() { configure_insta!(); let boot = boot_test::().await.unwrap(); - seed::(&boot.app_context.db).await.unwrap(); + seed::(&boot.app_context).await.unwrap(); // query your model, e.g.: // diff --git a/loco-gen/tests/templates/snapshots/generate[test_model]@Htmx_scaffold.snap b/loco-gen/tests/templates/snapshots/generate[test_model]@Htmx_scaffold.snap index e9c641f3..2b139301 100644 --- a/loco-gen/tests/templates/snapshots/generate[test_model]@Htmx_scaffold.snap +++ b/loco-gen/tests/templates/snapshots/generate[test_model]@Htmx_scaffold.snap @@ -20,7 +20,7 @@ async fn test_model() { configure_insta!(); let boot = boot_test::().await.unwrap(); - seed::(&boot.app_context.db).await.unwrap(); + seed::(&boot.app_context).await.unwrap(); // query your model, e.g.: // diff --git a/loco-gen/tests/templates/snapshots/generate[test_model]@model.snap b/loco-gen/tests/templates/snapshots/generate[test_model]@model.snap index 795cdb00..5f899688 100644 --- a/loco-gen/tests/templates/snapshots/generate[test_model]@model.snap +++ b/loco-gen/tests/templates/snapshots/generate[test_model]@model.snap @@ -20,7 +20,7 @@ async fn test_model() { configure_insta!(); let boot = boot_test::().await.unwrap(); - seed::(&boot.app_context.db).await.unwrap(); + seed::(&boot.app_context).await.unwrap(); // query your model, e.g.: // diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false_Sqlite.snap b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false_Sqlite.snap index 73c49b29..d36c51ac 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false_Sqlite.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_false_Sqlite.snap @@ -16,7 +16,6 @@ use loco_rs::{ Result, }; use migration::Migrator; -use sea_orm::DatabaseConnection; #[allow(unused_imports)] use crate::{ @@ -61,10 +60,10 @@ impl Hooks for App { fn register_tasks(tasks: &mut Tasks) { // tasks-inject (do not remove) } - async fn truncate(_db: &DatabaseConnection) -> Result<()> { + async fn truncate(_ctx: &AppContext) -> Result<()> { Ok(()) } - async fn seed(_db: &DatabaseConnection, _base: &Path) -> Result<()> { + async fn seed(_ctx: &AppContext, _base: &Path) -> Result<()> { Ok(()) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true_Sqlite.snap b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true_Sqlite.snap index d2424b6e..cafc3cd6 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true_Sqlite.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__auth__src_app_rs_auth_true_Sqlite.snap @@ -17,7 +17,6 @@ use loco_rs::{ Result, }; use migration::Migrator; -use sea_orm::DatabaseConnection; #[allow(unused_imports)] use crate::{ @@ -63,12 +62,12 @@ impl Hooks for App { fn register_tasks(tasks: &mut Tasks) { // tasks-inject (do not remove) } - async fn truncate(db: &DatabaseConnection) -> Result<()> { - truncate_table(db, users::Entity).await?; + async fn truncate(ctx: &AppContext) -> Result<()> { + truncate_table(&ctx.db, users::Entity).await?; Ok(()) } - async fn seed(db: &DatabaseConnection, base: &Path) -> Result<()> { - db::seed::(db, &base.join("users.yaml").display().to_string()).await?; + async fn seed(ctx: &AppContext, base: &Path) -> Result<()> { + db::seed::(&ctx.db, &base.join("users.yaml").display().to_string()).await?; Ok(()) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap index 78f653a6..6714b3a2 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Postgres.snap @@ -16,7 +16,6 @@ use loco_rs::{ Result, }; use migration::Migrator; -use sea_orm::DatabaseConnection; #[allow(unused_imports)] use crate::{ @@ -61,10 +60,10 @@ impl Hooks for App { fn register_tasks(tasks: &mut Tasks) { // tasks-inject (do not remove) } - async fn truncate(_db: &DatabaseConnection) -> Result<()> { + async fn truncate(_ctx: &AppContext) -> Result<()> { Ok(()) } - async fn seed(_db: &DatabaseConnection, _base: &Path) -> Result<()> { + async fn seed(_ctx: &AppContext, _base: &Path) -> Result<()> { Ok(()) } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap index 78f653a6..6714b3a2 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__db__src_app_rs_Sqlite.snap @@ -16,7 +16,6 @@ use loco_rs::{ Result, }; use migration::Migrator; -use sea_orm::DatabaseConnection; #[allow(unused_imports)] use crate::{ @@ -61,10 +60,10 @@ impl Hooks for App { fn register_tasks(tasks: &mut Tasks) { // tasks-inject (do not remove) } - async fn truncate(_db: &DatabaseConnection) -> Result<()> { + async fn truncate(_ctx: &AppContext) -> Result<()> { Ok(()) } - async fn seed(_db: &DatabaseConnection, _base: &Path) -> Result<()> { + async fn seed(_ctx: &AppContext, _base: &Path) -> Result<()> { Ok(()) } } diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 34f70a08..319950f4 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -55,11 +55,11 @@ //! //! fn register_tasks(tasks: &mut Tasks) {} //! -//! async fn truncate(db: &DatabaseConnection) -> Result<()> { +//! async fn truncate(_ctx: &AppContext) -> Result<()> { //! Ok(()) //! } //! -//! async fn seed(db: &DatabaseConnection, base: &Path) -> Result<()> { +//! async fn seed(_ctx: &AppContext, base: &Path) -> Result<()> { //! Ok(()) //! } //! } diff --git a/src/testing/db.rs b/src/testing/db.rs index 48bcda0a..dd2bba52 100644 --- a/src/testing/db.rs +++ b/src/testing/db.rs @@ -22,7 +22,7 @@ use crate::{ /// #[tokio::test] /// async fn test_create_user() { /// let boot = boot_test::().await; -/// seed::(&boot.app_context.db).await.unwrap(); +/// seed::(&boot.app_context).await.unwrap(); /// /// /// ..... /// assert!(false)