public void Upsert() { 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, "production", true) }) .In <Host>(); // execute query for the first time var firstResult = query.Select((n, o) => n).ToList(); Assert.Equal(firstResult.Count, 1); Assert.Equal(firstResult[0].Tags.Count, 1); Assert.Equal(firstResult[0].Tags[0], "development"); // execute query for the second time var secondResult = query.Select((n, o) => n).ToList(); Assert.Equal(secondResult.Count, 1); Assert.Equal(secondResult[0].Tags.Count, 2); Assert.Equal(secondResult[0].Tags[0], "development"); Assert.Equal(secondResult[0].Tags[1], "production"); }
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); }