Пример #1
0
        public NodeSet Match(NodeDescription nodeDescription)
        {
            if (nodeSets.Count == 0 && relationSets.Count == 0)
            {
                var nodeSet = FirstMatch(nodeDescription);
                nodeSets.Add(nodeSet);
                return(nodeSet);
            }

            if (nodeSets.Count != relationSets.Count)
            {
                throw new Exception("There cannot be 2 consecutive calls to Match(...) for one Query");
            }


            var lastRelationSet = relationSets.Last();

            var newLastNodeSet = new NodeSet();


            foreach (var relation in lastRelationSet.Relations)
            {
                var candidateNode = lastRelationSet.Direction == RelationsDirection.Right ? relation.To : relation.From;

                if (nodeDescription.CheckNode(candidateNode))
                {
                    newLastNodeSet.Nodes.Add(candidateNode);
                }
            }

            nodeSets.Add(newLastNodeSet);
            return(newLastNodeSet);
        }
Пример #2
0
        private NodeSet FirstMatch(NodeDescription nodeDescription)
        {
            var nodeBlocks = DbFetcher.SelectNodeBlocksByLabelAndProperties(nodeDescription.Label, nodeDescription.Props);

            var nodeSet = new NodeSet();

            foreach (var nodeBlock in nodeBlocks)
            {
                nodeSet.Nodes.Add(new Node(nodeBlock, db));
            }

            return(nodeSet);
        }
Пример #3
0
        private static void Main(string[] args)
        {
            using (var engine = new DbEngine())
            {
//                engine.DropDatabase();

                Node user1 = engine.AddNode("user");
                user1["age"] = 19;

                Node user2 = engine.AddNode("user");
                user2["age"] = 20;

                var relation1 = engine.AddRelation(user1, user2, "knows");
                relation1["some_property"] = "zzz";

                engine.SaveChanges();

                var query = new Query(engine);

                var firstNodeDescription = new NodeDescription(
                    "user",
                    new Dictionary <string, object>
                {
                    { "age", 19 }
                }
                    );

                var relationDescription = new RelationDescription(
                    "knows",
                    new Dictionary <string, object>
                {
                    { "some_property", "zzz" }
                }
                    );


                var a = query.Match(firstNodeDescription);
                var x = query.To(relationDescription);
                var b = query.Match(NodeDescription.Any());

                query.Execute();

                Console.WriteLine(a.Nodes.First()["age"]);
                Console.WriteLine(x.Relations.First()["some_property"]);
                Console.WriteLine(b.Nodes.First()["age"]);

                Console.ReadLine();

                engine.DropDatabase();
            }
        }