1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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<Child>,
- parents: microrm::IDMap<Parent>,
- }
- #[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)
- );
- }
|