Files
raven/server/AyaNova/biz/SqlSelectBuilder.cs
2020-01-16 00:06:27 +00:00

56 lines
1.5 KiB
C#

using System.Collections.Generic;
using System;
using System.Globalization;
using System.Text;
using Newtonsoft.Json.Linq;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace AyaNova.Biz
{
public static class SqlSelectBuilder
{
//Build the SELECT portion of a list query based on the template, mini or full and the object key in question
public static string Build(string objectKey, string template, bool mini)
{
//parse the template
var jtemplate = JObject.Parse(template);
//get the fields list
var FieldsList = ObjectFields.ObjectFieldsList(objectKey);
//convert to strings array (https://stackoverflow.com/a/33836599/8939)
string[] templateFieldList;
if (mini)
{
templateFieldList = ((JArray)jtemplate["mini"]).ToObject<string[]>();
}
else
{
templateFieldList = ((JArray)jtemplate["full"]).ToObject<string[]>();
}
StringBuilder sb = new StringBuilder();
sb.Append("SELECT ");
foreach (string ColumnName in templateFieldList)
{
//NOPE, NOPE, NOPE....rather than this, it needs to get the names by consulting the ObjectFields list which may contain overrides for the sql name etc
sb.Append(ColumnName);
}
return sb.ToString();
}
}//eoc
}//ens