I want to test a block of code that selects
before insert
. If the select
find the element by id then we don't insert. If we get None
then we can insert.
if TheEntity::find_by_id(id).one(&db).await?.is_some() {
//Do not insert and do other stuff...
}else{
//Insert the new entity.
}
How can I instruct MockDatabase
to return a no results
result?
MockDatabase::new(DatabaseBackend::Sqlite)
.append_query_results([
//Here instead of return this Model I want to return None.
vec![my_entity::Model{id: "TheId".to_string()}]
]);
I used an Empty vector and is working now...