Пример #1
0
        public void UpsertWithFor()
        {
            var db = DatabaseGenerator.Get();

            var query = db.Query <Host>()
                        .Upsert(h => new Host {
                Key = h.Key
            },
                                h => new Host {
            },
                                (h, old) => new Host {
                Tags = AQL.Append(h.Tags, old.Tags)
            });

            var queryData = query.GetQueryData();

            Assert.Equal(queryData.Query.RemoveSpaces(), @"
for `h` in `hosts`
upsert { `_key` : `h`.`_key` }
insert @P1
update { `tags` : append( `h`.`tags` , `OLD` .`tags` ) }
in `hosts`
".RemoveSpaces());

            ObjectUtility.AssertSerialize(queryData.BindVars[0].Value, new { }, db);
        }
Пример #2
0
        public void UpsertComplexUpdate()
        {
            var db = DatabaseGenerator.Get();

            var query = db.Query()
                        .Upsert <Host>(_ => new Host {
                Ip = "192.168.173.94"
            },
                                       _ => new Host {
                Ip = "192.168.173.94", Name = "chorweiler", Tags = new string[] { "development" }
            },
                                       (_, o) => new Host {
                Tags = AQL.Push(o.Tags, "development", true)
            })
                        .In <Host>().ReturnResult(true);

            var queryData = query.GetQueryData();

            Assert.Equal(queryData.Query.RemoveSpaces(), @"
upsert @P1
insert @P2
update { `tags` : push( `OLD` .`tags` , @P3 , @P4  )  }
in `hosts`
let crudResult = NEW 
return crudResult
                    ".RemoveSpaces());

            ObjectUtility.AssertSerialize(queryData.BindVars[0].Value, new { ip = "192.168.173.94" }, db);
            ObjectUtility.AssertSerialize(queryData.BindVars[1].Value, new { ip = "192.168.173.94", name = "chorweiler", tags = new string[] { "development" } }, db);
            Assert.Equal(queryData.BindVars[2].Value, "development");
            Assert.Equal(queryData.BindVars[3].Value, true);
        }