Exemple #1
0
        public void TestInsert()
        {
            arango.CreateCollection("stuff", CollectionType.Document);

            JsonObject obj = new JsonObject()
                             .Add("_key", "key")
                             .Add("foo", 42);

            Assert.AreEqual(
                "[42]".Replace("'", "\""),
                executor.ExecuteToArray(
                    new AqlQuery()
                    .Insert(obj).Into("stuff")
                    .Return((NEW) => NEW["foo"])
                    ).ToString()
                );

            Assert.AreEqual(
                "[42]".Replace("'", "\""),
                executor.ExecuteToArray(
                    new AqlQuery()
                    .Return(() => AF.Document("stuff", "key")["foo"])
                    ).ToString()
                );
        }
Exemple #2
0
        public void ItParsesArangoFunctions()
        {
            Assert.AreEqual(
                "DOCUMENT(\"users\", \"123\")",
                parser.Parse(() => AF.Document("users", "123")).ToAql()
                );

            Assert.AreEqual(
                "DOCUMENT(\"users\", x.foo)",
                parser.Parse((x) => AF.Document("users", x["foo"])).ToAql()
                );
        }
        /// <summary>
        /// Find the document of an entity by entity id
        /// </summary>
        internal JsonObject FindDocument(string entityId)
        {
            try
            {
                var id = DocumentId.Parse(entityId);
                id.ThrowIfHasNull();

                return(arango.ExecuteAqlQuery(new AqlQuery()
                                              .Return(() => AF.Document(id.Collection, id.Key))
                                              ).First().AsJsonObject);
            }
            catch (ArangoException e) when(e.ErrorNumber == 1203)
            {
                // collection or view not found
                return(null);
            }
        }
        public void ItEvaluatesArangoFunctions()
        {
            // overwrite DOCUMENT function implementation
            arango.FunctionRepository
            .Register("DOCUMENT", (args) => new JsonObject()
                      .Add("collection", args[0])
                      .Add("key", args[1])
                      );

            Assert.AreEqual(
                "{'collection':'foo','key':'bar'}".Replace("'", "\""),
                parser
                .Parse(() => AF.Document("foo", "bar"))
                .Evaluate(executor, frame)
                .ToString()
                );
        }
        public JsonObject Load(string sessionId)
        {
            try
            {
                JsonObject document = arango.ExecuteAqlQuery(
                    new AqlQuery()
                    .Return(() => AF.Document(CollectionName, sessionId))
                    ).First().AsJsonObject;

                return(document?["sessionData"].AsJsonObject
                       ?? new JsonObject());
            }
            catch (ArangoException e) when(e.ErrorNumber == 1203)
            {
                // collection or view not found
                return(new JsonObject());
            }
        }