浏览代码

Added nested schemata test.

Kestrel 3 周之前
父节点
当前提交
97fa9e3fb3
共有 1 个文件被更改,包括 68 次插入0 次删除
  1. 68 0
      microrm/tests/nested_schemata.rs

+ 68 - 0
microrm/tests/nested_schemata.rs

@@ -0,0 +1,68 @@
+mod common;
+use test_log::test;
+
+use microrm::prelude::*;
+
+#[derive(Entity)]
+struct Object {
+    written: String,
+}
+
+#[derive(Entity)]
+struct Subject {
+    written: String,
+}
+
+#[derive(Entity)]
+struct Verb {
+    written: String
+}
+
+#[derive(Default, Schema)]
+struct DictionarySchema {
+    objects: microrm::IDMap<Object>,
+    subjects: microrm::IDMap<Subject>,
+    verbs: microrm::IDMap<Verb>,
+}
+
+#[derive(Entity)]
+struct Sentence {
+    object: ObjectID,
+    subject: SubjectID,
+    verb: VerbID,
+}
+
+#[derive(Default, Schema)]
+struct SentenceSchema {
+    sentences: microrm::IDMap<Sentence>,
+}
+
+#[derive(Default, Schema)]
+struct CombinedSchema {
+    dictionary: DictionarySchema,
+    sentence: SentenceSchema,
+}
+
+#[test]
+fn nested() {
+    let (pool, db): (_, CombinedSchema) = common::open_test_db!();
+    let mut lease = pool.acquire().unwrap();
+
+    let obj_id = db.dictionary.objects.insert(&mut lease, Object {
+        written: String::from("an_object")
+    }).expect("couldn't insert object");
+
+    let subj_id = db.dictionary.subjects.insert(&mut lease, Subject {
+        written: String::from("a_subject")
+    }).expect("couldn't insert subject");
+
+    let verb_id = db.dictionary.verbs.insert(&mut lease, Verb {
+        written: String::from("verb1")
+    }).expect("couldn't insert verb");
+
+    db.sentence.sentences.insert(&mut lease, Sentence {
+        object: obj_id,
+        subject: subj_id,
+        verb: verb_id,
+    }).expect("couldn't insert sentence");
+}