2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-06 03:45:38 -04:00
|
|
|
module Gitlab
|
|
|
|
module SQL
|
|
|
|
module Glob
|
|
|
|
extend self
|
|
|
|
|
|
|
|
# Convert a simple glob pattern with wildcard (*) to SQL LIKE pattern
|
|
|
|
# with SQL expression
|
|
|
|
def to_like(pattern)
|
|
|
|
<<~SQL
|
|
|
|
REPLACE(REPLACE(REPLACE(#{pattern},
|
|
|
|
#{q('%')}, #{q('\\%')}),
|
|
|
|
#{q('_')}, #{q('\\_')}),
|
|
|
|
#{q('*')}, #{q('%')})
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def q(string)
|
|
|
|
ActiveRecord::Base.connection.quote(string)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|