public override string BuildSql(SqlOptions sqlOptions)
 {
     var columns = string.Join($",{sqlOptions.NewLine()}{sqlOptions.Indent()}",
         Entities.Select(e => e.BuildSql(sqlOptions, FlowOptions.Construct(this))));
     var command = sqlOptions.Command("VALUES");
     return $"{command} ({sqlOptions.NewLine()}{sqlOptions.Indent()}{columns}{sqlOptions.NewLine()})";
 }
Exemple #2
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            var orders = Entities.Select(s => s.BuildSql(sqlOptions, FlowOptions.Construct(this)));
            var order  = string.Join($",{sqlOptions.NewLine()}{sqlOptions.Indent()}", orders);

            return($"{sqlOptions.Command("ORDER BY")}{sqlOptions.NewLine()}{sqlOptions.Indent()}{order}");
        }
        public override string BuildSql(SqlOptions sqlOptions)
        {
            var keys    = string.Join($",{sqlOptions.NewLine()}{sqlOptions.Indent()}", Entities.Select(e => e.BuildSql(sqlOptions, FlowOptions.Construct(this))));
            var command = "RETURNING";

            return($"{command}{sqlOptions.NewLine()}{sqlOptions.Indent()}{keys}");
        }
Exemple #4
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            var entities = Entities.Select(c => $"{c.BuildSql(sqlOptions, FlowOptions.Construct(this))}");
            var columns  = string.Join($",{sqlOptions.NewLine()}{sqlOptions.Indent()}", entities);
            var command  = sqlOptions.Command("SET");

            return($"{command}{sqlOptions.NewLine()}{sqlOptions.Indent()}{columns}");
        }
Exemple #5
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            if (sqlOptions == null)
            {
                throw new ArgumentException(nameof(sqlOptions));
            }

            CheckBeforeBuild(sqlOptions);
            IEnumerable <SqlBuilderEntity> data = new SqlBuilderEntity[]
            {
                CustomBlocks[SqlInsertPosition.Start],
                InsertIntoBlock,
                CustomBlocks[SqlInsertPosition.Into],
                InsertColumnsBlock,
                InsertValuesBlock,
                CustomBlocks[SqlInsertPosition.Values],
                ConflictUpdate,
                CustomBlocks[SqlInsertPosition.Conflict],
                DoUpdateBlock,
                DoNothingBlock,
                CustomBlocks[SqlInsertPosition.Do],
                WhereBlock,
                CustomBlocks[SqlInsertPosition.Where],
                ReturningBlock,
                CustomBlocks[SqlInsertPosition.Return],
            };
            var commands = data.Where(b => CheckBlock(b, sqlOptions)).Select(b => b.BuildSql(sqlOptions, FlowOptions.Construct(this)));

            return(string.Join(sqlOptions.NewLine(), commands));
        }
Exemple #6
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            if (sqlOptions == null)
            {
                throw new ArgumentException(nameof(sqlOptions));
            }

            CheckBeforeBuild(sqlOptions);
            IEnumerable <SqlBuilderEntity> data = new SqlBuilderEntity[]
            {
                CustomSqlBlocks[SqlSelectPosition.Start],
                SelectValuesBlock,
                CustomSqlBlocks[SqlSelectPosition.Select],
                FromTablesBlock,
                CustomSqlBlocks[SqlSelectPosition.From],
                JoinsBlock,
                CustomSqlBlocks[SqlSelectPosition.Join],
                WhereBlock,
                CustomSqlBlocks[SqlSelectPosition.Where],
                OrdersBlock,
                CustomSqlBlocks[SqlSelectPosition.Order],
                OffsetBlock,
                CustomSqlBlocks[SqlSelectPosition.Offset],
                LimitBlock,
                CustomSqlBlocks[SqlSelectPosition.Limit]
            };
            var commands = data.Where(b => CheckBlock(b, sqlOptions)).Select(b => b.BuildSql(sqlOptions, FlowOptions.Construct(this)));

            return(string.Join(sqlOptions.NewLine(), commands));
        }
Exemple #7
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            if (sqlOptions == null)
            {
                throw new ArgumentException(nameof(sqlOptions));
            }

            CheckBeforeBuild(sqlOptions);

            IEnumerable <SqlBuilderEntity> data = new SqlBuilderEntity[]
            {
                CustomBlocks[SqlUpdatePosition.Start],
                UpdateTableBlock,
                CustomBlocks[SqlUpdatePosition.Table],
                ColumnsBlock,
                CustomBlocks[SqlUpdatePosition.Columns],
                WhereBlock,
                CustomBlocks[SqlUpdatePosition.Where],
                ReturningsBlock,
                CustomBlocks[SqlUpdatePosition.Return]
            };
            var commands = data.Where(b => CheckBlock(b, sqlOptions)).Select(b => b.BuildSql(sqlOptions, FlowOptions.Construct(this)));

            return(string.Join(sqlOptions.NewLine(), commands));
        }
        public override string BuildSql(SqlOptions sqlOptions)
        {
            var properties = string.Join($",{sqlOptions.NewLine()}{sqlOptions.Indent()}",
                                         Entities.Select(e => e.BuildSql(sqlOptions, FlowOptions.Construct(this))));
            string command;

            switch (sqlOptions.DatabaseType)
            {
            case SqlDatabaseType.Postgres:
            case SqlDatabaseType.SqLite:
                command = sqlOptions.Command("DO UPDATE SET");
                break;

            case SqlDatabaseType.MySql:
            case SqlDatabaseType.MariaDb:
                command = sqlOptions.Command("UPDATE");
                break;

            default: return(null);
            }

            return($"{command}{sqlOptions.NewLine()}{sqlOptions.Indent()}{properties}");
        }
Exemple #9
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            AndOperator andBlock;

            if (Entities.Count == 1 && Entities[0] is AndOperator andOperator)
            {
                andBlock = andOperator;
            }
            else
            {
                andBlock = new AndOperator(Entities);
            }
            andBlock.Indent  = true;
            andBlock.NewLine = true;
            var conditions = andBlock.BuildSql(sqlOptions, FlowOptions.Construct(this));
            var command    = sqlOptions.Command("WHERE");

            return($"{command}{sqlOptions.NewLine()}{sqlOptions.Indent("    ")}{conditions}");
        }
Exemple #10
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            if (sqlOptions == null)
            {
                throw new ArgumentException(nameof(sqlOptions));
            }

            var updatedSqlOptions = ((SqlOptions)sqlOptions.Clone()).WithoutTableNames();

            CheckBeforeBuild(updatedSqlOptions);
            IEnumerable <SqlBuilderEntity> data = new SqlBuilderEntity[]
            {
                CustomBlocks[SqlDeletePosition.Start],
                DeleteFromBlock,
                CustomBlocks[SqlDeletePosition.From],
                WhereBlock,
                CustomBlocks[SqlDeletePosition.Where],
                ReturningsBlock,
                CustomBlocks[SqlDeletePosition.Return]
            };
            var commands = data.Where(b => CheckBlock(b, updatedSqlOptions)).Select(b => b.BuildSql(updatedSqlOptions, FlowOptions.Construct(this)));

            return(string.Join(sqlOptions.NewLine(), commands));
        }
        public virtual string GetSeparator(SqlOptions sqlOptions)
        {
            var r = $"{(NewLine ? sqlOptions.NewLine() : "")}{(Indent ? sqlOptions.Indent() : "")}";

            return(string.IsNullOrEmpty(r) ? " " : r);
        }
        public override string BuildSql(SqlOptions sqlOptions)
        {
            var joins = Entities.Select(e => e.BuildSql(sqlOptions, FlowOptions.Construct(this)));

            return(string.Join(sqlOptions.NewLine(), joins));
        }
Exemple #13
0
        public override string BuildSql(SqlOptions sqlOptions)
        {
            var columns = string.Join($",{sqlOptions.NewLine()}{sqlOptions.Indent()}", Entities.Select(e => e.BuildSql(sqlOptions, FlowOptions.Construct(this))));

            return($"{sqlOptions.Command("SELECT")}{sqlOptions.NewLine()}{sqlOptions.Indent()}{columns}");
        }