using Connected.Expressions; using Connected.Expressions.Languages; using Connected.Expressions.Translation; using Connected.Expressions.TypeSystem; namespace Connected.ServiceModel.Client.Data; internal sealed class CqlLanguage : QueryLanguage { private static CqlLanguage? _default; static CqlLanguage() { SplitChars = new char[] { '.' }; } public CqlLanguage() { TypeSystem = new CqlTypeSystem(); } public override QueryTypeSystem TypeSystem { get; } private static char[] SplitChars { get; } public override bool AllowsMultipleCommands => true; public override bool AllowSubqueryInSelectWithoutFrom => true; public override bool AllowDistinctInAggregates => true; public static CqlLanguage Default { get { if (_default is null) Interlocked.CompareExchange(ref _default, new CqlLanguage(), null); return _default; } } public override string Quote(string name) { if (name.StartsWith("[") && name.EndsWith("]")) return name; else if (name.Contains('.')) return $"[{string.Join("].[", name.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries))}]"; else return $"[{name}]"; } public override Linguist CreateLinguist(ExpressionCompilationContext context, Translator translator) { return new CqlLinguist(context, this, translator); } }