Class: Ansr::ConnectionAdapters::NoSqlAdapter
- Inherits:
-
ActiveRecord::ConnectionAdapters::AbstractAdapter
- Object
- ActiveRecord::ConnectionAdapters::AbstractAdapter
- Ansr::ConnectionAdapters::NoSqlAdapter
- Defined in:
- lib/ansr/connection_adapters/no_sql_adapter.rb
Defined Under Namespace
Classes: BindSubstitution
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#columns(table_name, *rest) ⇒ Object
this is called by the BigTable impl should it be retired in favor of the more domain-appropriate ‘fields’? Not usually seen by clients anyway.
-
#execute(query, name = 'ANSR-NOSQL') ⇒ Object
Executes
query
statement in the context of this connection usingbinds
as the bind substitutes. -
#initialize(klass, connection, logger = nil, pool = nil) ⇒ NoSqlAdapter
constructor
A new instance of NoSqlAdapter.
-
#primary_key(table_name) ⇒ Object
called back from ::Arel::Table.
- #sanitize_filter_name(filter_value) ⇒ Object
- #sanitize_limit(limit_value) ⇒ Object
- #schema_cache ⇒ Object
- #table_exists?(name) ⇒ Boolean
-
#to_nosql(arel, binds = []) ⇒ Object
Converts an arel AST to NOSQL Query.
Constructor Details
#initialize(klass, connection, logger = nil, pool = nil) ⇒ NoSqlAdapter
Returns a new instance of NoSqlAdapter.
7 8 9 10 11 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 7 def initialize(klass, connection, logger = nil, pool = nil) super(connection, logger, pool) @table = klass.table @visitor = nil end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 6 def table @table end |
Instance Method Details
#columns(table_name, *rest) ⇒ Object
this is called by the BigTable impl should it be retired in favor of the more domain-appropriate ‘fields’? Not usually seen by clients anyway.
52 53 54 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 52 def columns(table_name, *rest) @table.fields.map {|s| ::ActiveRecord::ConnectionAdapters::Column.new(s.to_s, nil, String)} end |
#execute(query, name = 'ANSR-NOSQL') ⇒ Object
Executes query
statement in the context of this connection using binds
as the bind substitutes. name
is logged along with the executed query
statement.
34 35 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 34 def execute(query, name = 'ANSR-NOSQL') end |
#primary_key(table_name) ⇒ Object
called back from ::Arel::Table
38 39 40 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 38 def primary_key(table_name) 'id' # table.primary_key || 'id' end |
#sanitize_filter_name(filter_value) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 64 def sanitize_filter_name(filter_value) if filter_value.is_a? Array return filter_value.collect {|x| sanitize_filter_name(x)}.compact else if @table.facets.include? filter_value.to_sym return filter_value else raise "#{filter_value} is not a filterable field" #Rails.logger.warn "Ignoring #{filter_value} (not a filterable field)" if Rails.logger #return nil end end end |
#sanitize_limit(limit_value) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 56 def sanitize_limit(limit_value) if limit_value.to_s.to_i >= 0 limit_value else Ansr::Relation::DEFAULT_PAGE_SIZE end end |
#schema_cache ⇒ Object
46 47 48 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 46 def schema_cache ActiveRecord::ConnectionAdapters::SchemaCache.new(self) end |
#table_exists?(name) ⇒ Boolean
42 43 44 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 42 def table_exists?(name) true end |
#to_nosql(arel, binds = []) ⇒ Object
Converts an arel AST to NOSQL Query
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ansr/connection_adapters/no_sql_adapter.rb', line 14 def to_nosql(arel, binds = []) arel = arel.ast if arel.respond_to?(:ast) if arel.is_a? ::Arel::Nodes::Node binds = binds.dup visitor.accept(arel) do quote(*binds.shift.reverse) end else # assume it is already serialized arel end end |