Module: Gitlab::SQL::Glob

Extended by:
Glob
Included in:
Glob
Defined in:
lib/gitlab/sql/glob.rb

Instance Method Summary collapse

Instance Method Details

#q(string) ⇒ Object


19
20
21
# File 'lib/gitlab/sql/glob.rb', line 19

def q(string)
  ActiveRecord::Base.connection.quote(string)
end

#to_like(pattern) ⇒ Object

Convert a simple glob pattern with wildcard (*) to SQL LIKE pattern with SQL expression


10
11
12
13
14
15
16
17
# File 'lib/gitlab/sql/glob.rb', line 10

def to_like(pattern)
  <<~SQL
    REPLACE(REPLACE(REPLACE(#{pattern},
                            #{q('%')}, #{q('\\%')}),
                    #{q('_')}, #{q('\\_')}),
            #{q('*')}, #{q('%')})
  SQL
end