public void WriteSelectClause(CommandBuilder sql) { if (IncludeDataInTempTable) { // Basically if the data for the Include is coming from a // SelectMany() clause sql.Append("select data, "); } else { sql.Append($"select d.id, "); } sql.Append(_includes.Select(x => x.TempTableSelector).Join(", ")); sql.Append($"\nfrom (select * from {FromObject} d "); sql.Append("where "); Where.Apply(sql); if (Offset > 0 || Limit > 0) { var offsetParam = sql.AddParameter(Offset); var limitParam = sql.AddParameter(Limit); sql.Append(" OFFSET :"); sql.Append(offsetParam.ParameterName); sql.Append(" LIMIT :"); sql.Append(limitParam.ParameterName); } sql.Append(") d\n"); sql.Append(_includes.Select(x => x.LeftJoinExpression).Join("\n")); }
public void AppendWhere(CommandBuilder sql) { if (Where != null) { sql.Append(" where "); Where.Apply(sql); } }
private static void FunctionCompositionRoutine() { Func <int, int, IEnumerable <int> > range = Enumerable.Range; var handler = range.ForwardCompose(Select <int, int> .Apply(x => x * x * x)) .ForwardCompose(Select <int, int> .Apply(x => x / 2)) .ForwardCompose(Where <int> .Apply(x => x % 2 == 1)) .ForwardCompose(ForEach <int> .Apply(Console.WriteLine)); handler(1, 10); }
private static void BlockStyleRoutine() { var request = new RangeRequest { Start = 1, Count = 10 }; var handler = new RangeEnumerator().Forward(Select <int, int> .Apply(x => x * x * x)) .Forward(Select <int, int> .Apply(x => x / 2)) .Forward(Where <int> .Apply(x => x % 2 == 1)) .Forward(ForEach <int> .Apply(Console.WriteLine)); handler.Handle(request); }
protected virtual void configure(CommandBuilder sql, bool withStatistics) { if (Mode == StatementMode.CommonTableExpression) { sql.Append(Previous == null ? "WITH " : " , "); sql.Append(ExportName); sql.Append(" as (\n"); } SelectClause.WriteSelectClause(sql, withStatistics); if (Where != null) { sql.Append(" where "); Where.Apply(sql); } writeOrderClause(sql); if (Offset > 0) { // TODO -- need to add more overloads to avoid the type to DbType lookup var param = sql.AddParameter(Offset); sql.Append(" OFFSET :"); sql.Append(param.ParameterName); } if (Limit > 0) { var param = sql.AddParameter(Limit); sql.Append(" LIMIT :"); sql.Append(param.ParameterName); } if (Mode == StatementMode.CommonTableExpression) { sql.Append("\n)\n"); } }
protected override void configure(CommandBuilder sql) { startCommonTableExpression(sql); sql.Append("select ctid, "); sql.Append(_field.LocatorForFlattenedElements); sql.Append(" as data from "); sql.Append(_sourceTable); if (Where != null) { sql.Append(" as d WHERE "); Where.Apply(sql); endCommonTableExpression(sql); } else { endCommonTableExpression(sql, " as d"); } }