|
@@ -19,10 +19,26 @@ struct DoubleItem {
|
|
|
v: usize,
|
|
|
}
|
|
|
|
|
|
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Value)]
|
|
|
+enum ExampleEnum {
|
|
|
+ Value1,
|
|
|
+ Value2,
|
|
|
+ Value3,
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(Entity)]
|
|
|
+struct SerializedItem {
|
|
|
+ #[key]
|
|
|
+ discrim: usize,
|
|
|
+ #[key]
|
|
|
+ e: ExampleEnum,
|
|
|
+}
|
|
|
+
|
|
|
#[derive(Database)]
|
|
|
struct ItemDB {
|
|
|
single_items: microrm::IDMap<SingleItem>,
|
|
|
double_items: microrm::IDMap<DoubleItem>,
|
|
|
+ serialized_items: microrm::IDMap<SerializedItem>,
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
@@ -117,6 +133,57 @@ fn double_item() {
|
|
|
.is_none());
|
|
|
}
|
|
|
|
|
|
+#[test]
|
|
|
+fn serialized_test() {
|
|
|
+ let db: ItemDB = common::open_test_db!();
|
|
|
+
|
|
|
+ db.serialized_items
|
|
|
+ .insert(SerializedItem {
|
|
|
+ discrim: 0,
|
|
|
+ e: ExampleEnum::Value1.into(),
|
|
|
+ })
|
|
|
+ .expect("couldn't insert test item");
|
|
|
+
|
|
|
+ db.serialized_items
|
|
|
+ .insert(SerializedItem {
|
|
|
+ discrim: 1,
|
|
|
+ e: ExampleEnum::Value1.into(),
|
|
|
+ })
|
|
|
+ .expect("couldn't insert test item");
|
|
|
+
|
|
|
+ db.serialized_items
|
|
|
+ .insert(SerializedItem {
|
|
|
+ discrim: 1,
|
|
|
+ e: ExampleEnum::Value2.into(),
|
|
|
+ })
|
|
|
+ .expect("couldn't insert test item");
|
|
|
+
|
|
|
+ assert!(db
|
|
|
+ .serialized_items
|
|
|
+ .with(SerializedItem::E, ExampleEnum::Value1)
|
|
|
+ .keyed((1, ExampleEnum::Value1))
|
|
|
+ .first()
|
|
|
+ .get()
|
|
|
+ .expect("couldn't query db")
|
|
|
+ .is_some());
|
|
|
+ assert!(db
|
|
|
+ .serialized_items
|
|
|
+ .with(SerializedItem::E, ExampleEnum::Value1)
|
|
|
+ .keyed((1024, ExampleEnum::Value1))
|
|
|
+ .first()
|
|
|
+ .get()
|
|
|
+ .expect("couldn't query db")
|
|
|
+ .is_none());
|
|
|
+ assert!(db
|
|
|
+ .serialized_items
|
|
|
+ .with(SerializedItem::E, ExampleEnum::Value1)
|
|
|
+ .keyed((0, ExampleEnum::Value2))
|
|
|
+ .first()
|
|
|
+ .get()
|
|
|
+ .expect("couldn't query db")
|
|
|
+ .is_none());
|
|
|
+}
|
|
|
+
|
|
|
#[test]
|
|
|
fn with_test() {
|
|
|
let db: ItemDB = common::open_test_db!();
|