module CommandSearch

NOTE: This module supports does not support MariaDB or eariler Mysql versions than 8.0, due to changes in how word breaks are handled in regexes.

NOTE: This module supports MariaDB and MySql 5 with its distinct word break regex rules.

Public Instance Methods

build(type, query, options) click to toggle source
# File lib/command_search.rb, line 19
def build(type, query, options)
  aliases = options[:aliases] || {}
  fields = options[:fields] || {}
  aliased_query = Aliaser.alias(query, aliases)
  ast = Lexer.lex(aliased_query)
  Parser.parse!(ast)
  Optimizer.optimize!(ast)
  if type == :postgres
    Normalizer.normalize!(ast, fields)
    return Postgres.build_query(ast)
  end
  if type == :sqlite
    Normalizer.normalize!(ast, fields)
    return Sqlite.build_query(ast)
  end
  if type == :mysql
    Normalizer.normalize!(ast, fields)
    return Mysql.build_query(ast)
  end
  if type == :mysqlV5
    Normalizer.normalize!(ast, fields)
    return MysqlV5.build_query(ast)
  end
  Normalizer.normalize!(ast, fields, true)
  return Mongoer.build_query(ast) if type == :mongo
  ast
end