Trait green_barrel::models::fixtures::Fixtures
source · pub trait Fixtures: Caching + QPaladins + QCommons {
// Provided method
fn run_fixture<'life0, 'life1, 'async_trait>(
client: &'life0 Client,
fixture_name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error>>> + 'async_trait>>
where Self: Serialize + DeserializeOwned + Sized + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}
Expand description
To populate the database with pre-created data.
1.Create a fixtures folder at the root of the project. 2.Save data files for Models in it.
Example:
// Initial data for Model.
// ./fixtures/cities.json
[
{
"city_name": "London",
"description": "London is the capital city of England and the United Kingdom.",
},
{
"city_name": "Dresden",
"description": "Dresden is the capital of the East German state of Saxony.",
}
]
// Run fixtures
async fn run_migration() -> Result<(), Box<dyn Error>> {
...
let fixture_name = "cities";
ModelName::run_fixture(&client, fixture_name).await?;
Ok(())
}