# File lib/ansr/connection_adapters/no_sql_adapter.rb, line 38 def primary_key(table_name) 'id' # table.primary_key || 'id' end
class Ansr::ConnectionAdapters::NoSqlAdapter
Attributes
table[R]
Public Class Methods
new(klass, connection, logger = nil, pool = nil)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
columns(table_name, *rest)
click to toggle source
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.
# 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')
click to toggle source
Executes query
statement in the context of this connection using binds
as the bind substitutes. name
is logged along with the executed query
statement.
# File lib/ansr/connection_adapters/no_sql_adapter.rb, line 34 def execute(query, name = 'ANSR-NOSQL') end
primary_key(table_name)
click to toggle source
called back from ::Arel::Table
sanitize_filter_name(filter_value)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/ansr/connection_adapters/no_sql_adapter.rb, line 46 def schema_cache ActiveRecord::ConnectionAdapters::SchemaCache.new(self) end
table_exists?(name)
click to toggle source
# File lib/ansr/connection_adapters/no_sql_adapter.rb, line 42 def table_exists?(name) true end
to_nosql(arel, binds = [])
click to toggle source
Converts an arel AST to NOSQL Query
# 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