2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-12 10:16:49 -05:00
|
|
|
module Gitlab
|
|
|
|
module SQL
|
|
|
|
# Class for building SQL UNION statements.
|
|
|
|
#
|
2021-03-29 08:09:14 -04:00
|
|
|
# By default ORDER BYs are dropped from the relations as the final sort
|
|
|
|
# order is not guaranteed any way.
|
2015-11-12 10:16:49 -05:00
|
|
|
#
|
|
|
|
# Example usage:
|
|
|
|
#
|
2019-01-17 09:35:23 -05:00
|
|
|
# union = Gitlab::SQL::Union.new([user.personal_projects, user.projects])
|
2015-11-12 10:16:49 -05:00
|
|
|
# sql = union.to_sql
|
|
|
|
#
|
|
|
|
# Project.where("id IN (#{sql})")
|
2020-09-02 08:10:35 -04:00
|
|
|
class Union < SetOperator
|
|
|
|
def self.operator_keyword
|
|
|
|
'UNION'
|
2015-11-12 10:16:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|