use microrm::prelude::*; use test_log::test; mod common; #[derive(Entity)] struct Child { #[key] name: String, parent: ParentID, } #[derive(Entity)] struct Parent { name: String, } #[derive(Default, Schema)] struct PeopleDB { children: microrm::IDMap, parents: microrm::IDMap, } #[test] fn simple_query() { let (pool, db): (_, PeopleDB) = common::open_test_db!(); let mut lease = pool.acquire().unwrap(); let pid = db .parents .insert( &mut lease, Parent { name: "parent1".to_string(), }, ) .unwrap(); let _c1id = db .children .insert( &mut lease, Child { name: "child1".to_string(), parent: pid, }, ) .unwrap(); assert_eq!( db.children .foreign(Child::Parent) .get_ids(&mut lease) .expect("couldn't run query"), vec![pid] ); assert_eq!( db.children .keyed("child1") .foreign(Child::Parent) .get_ids(&mut lease) .expect("couldn't run query"), Some(pid) ); }