Class: DataMapper::Adapters::Tokyo::Query
- Inherits:
-
Object
- Object
- DataMapper::Adapters::Tokyo::Query
- Includes:
- Query::Conditions, Extlib::Assertions
- Defined in:
- lib/dm-tokyo-adapter/query.rb
Overview
Query a Tokyo Cabinet table store with a DataMapper query.
Notes
Query conditions not supported natively by TC’s table query will fall back to DM’s in-memory query filtering. This may impact performance.
Instance Method Summary collapse
-
#initialize(connection, query) ⇒ Query
constructor
A new instance of Query.
- #native? ⇒ Boolean
-
#read ⇒ Object
– TODO: connection[] if I have everything I need to fetch by the primary key.
Constructor Details
#initialize(connection, query) ⇒ Query
Returns a new instance of Query.
15 16 17 18 19 |
# File 'lib/dm-tokyo-adapter/query.rb', line 15 def initialize(connection, query) assert_kind_of 'connection', connection, Rufus::Tokyo::Table assert_kind_of 'query', query, DataMapper::Query @connection, @query, @native = connection, query, [] end |
Instance Method Details
#native? ⇒ Boolean
56 57 58 |
# File 'lib/dm-tokyo-adapter/query.rb', line 56 def native? @native.empty? end |
#read ⇒ Object
– TODO: connection[] if I have everything I need to fetch by the primary key.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dm-tokyo-adapter/query.rb', line 23 def read records = @connection.query do |statements| if @query.conditions.kind_of?(OrOperation) fail_native("Operation '#{@query.conditions.slug}'.") else @query.conditions.each do |condition| condition_statement(statements, condition) end end if native? && !@query.order.empty? sort_statement(statements, @query.order) end statements.limit(@query.limit) if native? && @query.limit statements.no_pk end records.each do |record| @query.fields.each do |property| field = property.field record[field] = property.typecast(record[field]) end end return records if native? # TODO: Move log entry out to adapter sublcass and use #name? DataMapper.logger.warn( "TokyoAdapter: No native TableQuery support for conditions: #{@native.join(' ')}" ) @query.filter_records(records) end |