use microrm::prelude::*; use microrm_macros::index_cols; use test_log::test; use microrm::schema::index::Index; mod common; #[derive(Entity)] struct TwoWay { up: String, left: String, right: String, } #[derive(Default, Schema)] struct TWDB { entries: microrm::IDMap, left_index: Index, right_index: Index, } #[test] fn db_construction() { let (_, _db): (_, TWDB) = common::open_test_db!(); } #[test] fn lookup() { let (pool, db): (_, TWDB) = common::open_test_db!(); let mut lease = pool.acquire().unwrap(); let e1 = db .entries .insert_and_return( &mut lease, TwoWay { up: "up1".into(), left: "left1".into(), right: "right1".into(), }, ) .expect("couldn't insert entry"); let e2 = db .entries .insert_and_return( &mut lease, TwoWay { up: "up2".into(), left: "left2".into(), right: "right2".into(), }, ) .expect("couldn't insert entry"); assert!(db .entries .indexed(&db.left_index, "left3") .get(&mut lease) .expect("couldn't query left index") .is_none()); assert_eq!( db.entries .indexed(&db.left_index, "left2") .get(&mut lease) .expect("couldn't query left index") .as_ref(), Some(&e2) ); assert_eq!( db.entries .indexed(&db.left_index, "left1") .get(&mut lease) .expect("couldn't query left index") .as_ref(), Some(&e1) ); assert!(db .entries .indexed(&db.right_index, "right3") .get(&mut lease) .expect("couldn't query right index") .is_none()); assert_eq!( db.entries .indexed(&db.right_index, "right2") .get(&mut lease) .expect("couldn't query right index") .as_ref(), Some(&e2) ); assert_eq!( db.entries .indexed(&db.right_index, "right1") .get(&mut lease) .expect("couldn't query right index") .as_ref(), Some(&e1) ); }