public QueryInsert(Execute.Executer executer, JObject query) : base(executer, query) { // data 절 JToken dataToken = JsonQuery.GetProperty("data").Value; if (dataToken is JValue) { string data = (string)dataToken; if (data.Length > 0 && data[0] == '@') { List <DataObject> resultSet; if (ParentExecuter.ResultSets.TryGetValue(data, out resultSet) == false) { throw new AegisException(RoseResult.InvalidArgument, $"{data} is not exist name."); } foreach (var item in resultSet) { Data.Add(JObject.Parse(item.Data)); } } else { throw new AegisException(RoseResult.InvalidArgument, $"{data} is not valid name."); } } else if (dataToken is JObject) { Data.Add(dataToken); } else if (dataToken is JArray) { foreach (var item in dataToken) { Data.Add(item); } } UniqueFor = (string)JsonQuery.GetProperty("uniqueFor", false)?.Value ?? null; OnDuplicate = (string)JsonQuery.GetProperty("onDuplicate", false)?.Value ?? null; if (OnDuplicate == null) { OnDuplicate = "ignore"; } if (OnDuplicate != "ignore" && OnDuplicate != "update") { throw new AegisException(RoseResult.InvalidArgument, "onDuplicate value must be 'ignore' or 'update'."); } }
public QueryUpdate(Execute.Executer executer, JObject query) : base(executer, query) { // data 절 JToken dataToken = JsonQuery.GetProperty("data").Value; if (dataToken is JValue) { string data = (string)dataToken; if (data.Length > 0 && data[0] == '@') { List <DataObject> resultSet; if (ParentExecuter.ResultSets.TryGetValue(data, out resultSet) == false) { throw new AegisException(RoseResult.InvalidArgument, $"{data} is not exist name."); } if (resultSet.Count() > 1) { JArray arr = new JArray(); foreach (var item in resultSet) { arr.Add(JObject.Parse(item.Data)); } Data = arr; } else if (resultSet.Count() == 1) { Data = JObject.Parse(resultSet.First().Data); } else { Data = JArray.Parse("[]"); } } else { throw new AegisException(RoseResult.InvalidArgument, $"{data} is not valid name."); } } else if (dataToken is JObject) { Data = dataToken; } else if (dataToken is JArray) { Data = dataToken.DeepClone(); } }
public QuerySelect(Execute.Executer executer, JObject query) : base(executer, query) { // sortKey 절 var sortKey = JsonQuery.GetProperty("sortKey", false)?.Value; if (sortKey != null) { if (sortKey is JValue) { var item = ((string)sortKey).Split(' '); if (item.Count() == 0 || item.Count() > 2) { throw new AegisException(RoseResult.InvalidArgument, "'sortKey' is must have one or two arguments."); } string orderBy = (item.Count() >= 2 ? item[1] : "asc"); if (orderBy != "asc" && orderBy != "desc") { throw new AegisException(RoseResult.InvalidArgument, $"'orderBy' is must be 'asc' or 'desc'."); } SortKeys = new SortKey[1]; SortKeys[0] = new SortKey() { Key = item[0], OrderBy = orderBy }; } else if (sortKey is JArray) { int index = 0; SortKeys = new SortKey[sortKey.Count()]; foreach (var key in sortKey) { var item = ((string)key).Split(' '); if (item.Count() == 0 || item.Count() > 2) { throw new AegisException(RoseResult.InvalidArgument, "'sortKey' is must have one or two arguments."); } string orderBy = (item.Count() >= 2 ? item[1] : "asc"); if (orderBy != "asc" && orderBy != "desc") { throw new AegisException(RoseResult.InvalidArgument, $"'orderBy' is must be 'asc' or 'desc'."); } SortKeys[index++] = new SortKey() { Key = item[0], OrderBy = orderBy }; } } } // range 절 var range = JsonQuery.GetProperty("range", false)?.Value as JArray; if (range != null) { if (range.Count() != 2) { throw new AegisException(RoseResult.InvalidArgument, $"'range' is must have two arguments."); } RangeStart = range.ElementAt(0).ToString().ToInt32(); RangeCount = range.ElementAt(1).ToString().ToInt32(); if (RangeStart < 0 || RangeCount < 0) { throw new AegisException(RoseResult.InvalidArgument, $"Argument of 'range' is not valid."); } } else { RangeStart = -1; RangeCount = -1; } }