Module: CommandSearch
- Defined in:
- lib/command_search.rb,
lib/command_search/lexer.rb,
lib/command_search/parser.rb,
lib/command_search/aliaser.rb,
lib/command_search/optimizer.rb,
lib/command_search/normalizer.rb,
lib/command_search/backends/mysql.rb,
lib/command_search/backends/memory.rb,
lib/command_search/backends/sqlite.rb,
lib/command_search/backends/mongoer.rb,
lib/command_search/backends/postgres.rb
Defined Under Namespace
Modules: Aliaser, Lexer, Memory, Mongoer, Mysql, Normalizer, Optimizer, Parser, Postgres, Sqlite
Class Method Summary
collapse
Class Method Details
.build(type, query, options) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/command_search.rb', line 18
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, false)
return Postgres.build_query(ast)
end
if type == :sqlite
Normalizer.normalize!(ast, fields, false)
return Sqlite.build_query(ast)
end
if type == :mysql
Normalizer.normalize!(ast, fields, false)
return Mysql.build_query(ast)
end
Normalizer.normalize!(ast, fields)
return Mongoer.build_query(ast) if type == :mongo
ast
end
|
.search(source, query, options) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/command_search.rb', line 42
def search(source, query, options)
if source.respond_to?(:mongo_client) && source.queryable
ast = CommandSearch.build(:mongo, query, options)
return source.where(ast)
end
if source.respond_to?(:postgresql_connection)
ast = CommandSearch.build(:postgres, query, options)
return source.where(ast)
end
if source.respond_to?(:sqlite3_connection)
ast = CommandSearch.build(:sqlite, query, options)
return source.where(ast)
end
if source.respond_to?(:mysql2_connection)
ast = CommandSearch.build(:mysql, query, options)
return source.where(ast)
end
ast = CommandSearch.build(:other, query, options)
source.select { |x| CommandSearch::Memory.check(x, ast) }
end
|