wip: add delete support to the simulator

This commit is contained in:
alpaylan
2025-02-07 08:19:00 -05:00
parent 8787ed11e2
commit 9c339cb8e1
4 changed files with 17 additions and 4 deletions

2
Cargo.lock generated
View File

@@ -1735,6 +1735,8 @@ dependencies = [
"notify",
"rand 0.8.5",
"rand_chacha 0.3.1",
"regex",
"regex-syntax",
"serde",
"serde_json",
"tempfile",

View File

@@ -14,7 +14,10 @@ use crate::{
use crate::generation::{frequency, Arbitrary, ArbitraryFrom};
use super::property::{remaining, Property};
use super::{
property::{remaining, Property},
table,
};
pub(crate) type ResultSet = Result<Vec<Vec<Value>>>;
@@ -303,7 +306,15 @@ impl Interactions {
.unwrap();
table.rows.extend(values);
}
Query::Delete(_) => todo!(),
Query::Delete(delete) => {
let table = env
.tables
.iter_mut()
.find(|t| t.name == delete.table)
.unwrap();
let t2 = &table.clone();
table.rows.retain_mut(|r| delete.predicate.test(r, t2));
}
Query::Select(_) => {}
},
Interaction::Assertion(_) => {}

View File

@@ -113,7 +113,7 @@ impl ArbitraryFrom<(&SimulatorEnv, &Remaining)> for Query {
Box::new(|rng| Self::Insert(Insert::arbitrary_from(rng, env))),
),
(
0.0,
remaining.write,
Box::new(|rng| Self::Delete(Delete::arbitrary_from(rng, env))),
),
],

View File

@@ -288,7 +288,7 @@ pub(crate) struct Delete {
impl Delete {
pub(crate) fn shadow(&self, _env: &mut SimulatorEnv) -> Vec<Vec<Value>> {
todo!()
vec![]
}
}