func (this *QueryBuilder) Union(query *db.Query) { unions := query.GetUnions() for _, u := range unions { this.unionPart.Add(" UNION ") if u.All { this.unionPart.Add("ALL ") } this.unionPart.Add(this.translator.GetSqlForQuery(u.Query)) } }
func (this *GenericTranslator) GetSqlForQuery(query *db.Query) string { proc := this.CreateQueryProcessor(query) // SELECT COLUNAS sel := tk.NewStrBuffer() sel.Add("SELECT ") if query.IsDistinct() { sel.Add("DISTINCT ") } sel.Add(proc.ColumnPart()) // FROM sel.Add(" FROM ", proc.FromPart()) // JOINS sel.Add(proc.JoinPart()) // WHERE - conditions if query.GetCriteria() != nil { sel.Add(" WHERE ", proc.WherePart()) } // GROUP BY if len(query.GetGroupBy()) != 0 { sel.Add(" GROUP BY ", proc.GroupPart()) } // HAVING if query.GetHaving() != nil { sel.Add(" HAVING ", proc.HavingPart()) } // UNION if len(query.GetUnions()) != 0 { sel.Add(proc.UnionPart()) } // ORDER if len(query.GetOrders()) != 0 { sel.Add(" ORDER BY ", proc.OrderPart()) } sql := this.overrider.PaginateSQL(query, sel.String()) return sql }