(ctx: &ReducerContext, arg: TestAlias, arg2: TestB, arg3: TestC, arg4: TestF)
| 301 | |
| 302 | #[spacetimedb::reducer] |
| 303 | pub fn test(ctx: &ReducerContext, arg: TestAlias, arg2: TestB, arg3: TestC, arg4: TestF) -> anyhow::Result<()> { |
| 304 | log::info!("BEGIN"); |
| 305 | log::info!("sender: {:?}", ctx.sender()); |
| 306 | log::info!("timestamp: {:?}", ctx.timestamp); |
| 307 | log::info!("bar: {:?}", arg2.foo); |
| 308 | |
| 309 | match arg3 { |
| 310 | TestC::Foo => log::info!("Foo"), |
| 311 | TestC::Bar => log::info!("Bar"), |
| 312 | } |
| 313 | match arg4 { |
| 314 | TestF::Foo => log::info!("Foo"), |
| 315 | TestF::Bar => log::info!("Bar"), |
| 316 | TestF::Baz(string) => log::info!("{string}"), |
| 317 | } |
| 318 | for i in 0..1000 { |
| 319 | ctx.db.test_a().insert(TestA { |
| 320 | x: i + arg.x, |
| 321 | y: i + arg.y, |
| 322 | z: "Yo".to_owned(), |
| 323 | }); |
| 324 | } |
| 325 | |
| 326 | let row_count_before_delete = ctx.db.test_a().count(); |
| 327 | |
| 328 | log::info!("Row count before delete: {row_count_before_delete:?}"); |
| 329 | |
| 330 | let mut num_deleted = 0; |
| 331 | for row in 5..10u32 { |
| 332 | num_deleted += ctx.db.test_a().foo().delete(row); |
| 333 | } |
| 334 | |
| 335 | let row_count_after_delete = ctx.db.test_a().count(); |
| 336 | |
| 337 | if row_count_before_delete != row_count_after_delete + num_deleted { |
| 338 | log::error!( |
| 339 | "Started with {row_count_before_delete} rows, deleted {num_deleted}, and wound up with {row_count_after_delete} rows... huh?", |
| 340 | ); |
| 341 | } |
| 342 | |
| 343 | match ctx.db.test_e().try_insert(TestE { |
| 344 | id: 0, |
| 345 | name: "Tyler".to_owned(), |
| 346 | }) { |
| 347 | Ok(x) => log::info!("Inserted: {x:?}"), |
| 348 | Err(err) => log::info!("Error: {err:?}"), |
| 349 | } |
| 350 | |
| 351 | log::info!("Row count after delete: {row_count_after_delete:?}"); |
| 352 | |
| 353 | let other_row_count = ctx |
| 354 | .db |
| 355 | .test_a() |
| 356 | // .iter() |
| 357 | // .filter(|row| row.x >= 0 && row.x <= u32::MAX) |
| 358 | .count(); |
| 359 | |
| 360 | log::info!("Row count filtered by condition: {other_row_count:?}"); |
searching dependent graphs…