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