Skip to content

Commit

Permalink
more docs + snap
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad committed Jan 8, 2025
1 parent 1563fdf commit 3ef5baa
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs-site/content/docs/the-app/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<users::ActiveModel>(db, &base.join("users.yaml").display().to_string()).await?;
async fn seed(ctx: &AppContext, base: &Path) -> Result<()> {
db::seed::<users::ActiveModel>(&ctx.db, &base.join("users.yaml").display().to_string()).await?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion loco-gen/src/templates/model/test.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn test_model() {
configure_insta!();

let boot = boot_test::<App>().await.unwrap();
seed::<App>(&boot.app_context.db).await.unwrap();
seed::<App>(&boot.app_context).await.unwrap();

// query your model, e.g.:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn test_model() {
configure_insta!();

let boot = boot_test::<App>().await.unwrap();
seed::<App>(&boot.app_context.db).await.unwrap();
seed::<App>(&boot.app_context).await.unwrap();

// query your model, e.g.:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn test_model() {
configure_insta!();

let boot = boot_test::<App>().await.unwrap();
seed::<App>(&boot.app_context.db).await.unwrap();
seed::<App>(&boot.app_context).await.unwrap();

// query your model, e.g.:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn test_model() {
configure_insta!();

let boot = boot_test::<App>().await.unwrap();
seed::<App>(&boot.app_context.db).await.unwrap();
seed::<App>(&boot.app_context).await.unwrap();

// query your model, e.g.:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn test_model() {
configure_insta!();

let boot = boot_test::<App>().await.unwrap();
seed::<App>(&boot.app_context.db).await.unwrap();
seed::<App>(&boot.app_context).await.unwrap();

// query your model, e.g.:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use loco_rs::{
Result,
};
use migration::Migrator;
use sea_orm::DatabaseConnection;

#[allow(unused_imports)]
use crate::{
Expand Down Expand Up @@ -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(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use loco_rs::{
Result,
};
use migration::Migrator;
use sea_orm::DatabaseConnection;

#[allow(unused_imports)]
use crate::{
Expand Down Expand Up @@ -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::<users::ActiveModel>(db, &base.join("users.yaml").display().to_string()).await?;
async fn seed(ctx: &AppContext, base: &Path) -> Result<()> {
db::seed::<users::ActiveModel>(&ctx.db, &base.join("users.yaml").display().to_string()).await?;
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use loco_rs::{
Result,
};
use migration::Migrator;
use sea_orm::DatabaseConnection;

#[allow(unused_imports)]
use crate::{
Expand Down Expand Up @@ -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(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use loco_rs::{
Result,
};
use migration::Migrator;
use sea_orm::DatabaseConnection;

#[allow(unused_imports)]
use crate::{
Expand Down Expand Up @@ -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(())
}
}
4 changes: 2 additions & 2 deletions src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
//! }
//! }
Expand Down
2 changes: 1 addition & 1 deletion src/testing/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
/// #[tokio::test]
/// async fn test_create_user() {
/// let boot = boot_test::<App, Migrator>().await;
/// seed::<App>(&boot.app_context.db).await.unwrap();
/// seed::<App>(&boot.app_context).await.unwrap();
///
/// /// .....
/// assert!(false)
Expand Down

0 comments on commit 3ef5baa

Please sign in to comment.