Pass Collection object, not name, to query so that we can access its hint fields at query time.
This commit is contained in:
parent
1afd968f5d
commit
61a0244c4c
|
@ -66,7 +66,7 @@ module XGen
|
||||||
# Return an array contining current profiling information from the
|
# Return an array contining current profiling information from the
|
||||||
# database.
|
# database.
|
||||||
def profiling_info
|
def profiling_info
|
||||||
@db.query(DB::SYSTEM_PROFILE_COLLECTION, Query.new({})).to_a
|
@db.query(Collection.new(@db, DB::SYSTEM_PROFILE_COLLECTION), Query.new({})).to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validate a named collection by raising an exception if there is a
|
# Validate a named collection by raising an exception if there is a
|
||||||
|
|
|
@ -25,6 +25,9 @@ module XGen
|
||||||
|
|
||||||
attr_reader :db, :name
|
attr_reader :db, :name
|
||||||
|
|
||||||
|
# A single field name or array of field names. May be +nil+.
|
||||||
|
attr_accessor :hint_fields
|
||||||
|
|
||||||
def initialize(db, name)
|
def initialize(db, name)
|
||||||
@db = db
|
@db = db
|
||||||
@name = name
|
@name = name
|
||||||
|
@ -47,7 +50,7 @@ module XGen
|
||||||
limit = options.delete(:limit) || 0
|
limit = options.delete(:limit) || 0
|
||||||
sort = options.delete(:sort)
|
sort = options.delete(:sort)
|
||||||
raise RuntimeError, "Unknown options [#{options.inspect}]" unless options.empty?
|
raise RuntimeError, "Unknown options [#{options.inspect}]" unless options.empty?
|
||||||
@db.query(@name, Query.new(selector, fields, offset, limit, sort))
|
@db.query(self, Query.new(selector, fields, offset, limit, sort))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Insert +objects+, which are hashes. "<<" is aliased to this method.
|
# Insert +objects+, which are hashes. "<<" is aliased to this method.
|
||||||
|
|
|
@ -31,6 +31,9 @@ module XGen
|
||||||
|
|
||||||
attr_reader :db, :collection, :query_message
|
attr_reader :db, :collection, :query_message
|
||||||
|
|
||||||
|
# A single field name or array of field names. May be +nil+.
|
||||||
|
attr_accessor :hint_fields
|
||||||
|
|
||||||
def initialize(db, collection, query_message)
|
def initialize(db, collection, query_message)
|
||||||
@db, @collection, @query_message = db, collection, query_message
|
@db, @collection, @query_message = db, collection, query_message
|
||||||
@num_to_return = query_message.query.number_to_return || 0
|
@num_to_return = query_message.query.number_to_return || 0
|
||||||
|
@ -110,7 +113,7 @@ module XGen
|
||||||
sel = OrderedHash.new
|
sel = OrderedHash.new
|
||||||
sel['query'] = @query_message.query.selector
|
sel['query'] = @query_message.query.selector
|
||||||
sel['$explain'] = true
|
sel['$explain'] = true
|
||||||
c = Cursor.new(@db, @collection, QueryMessage.new(@db.name, @collection, Query.new(sel)))
|
c = Cursor.new(@db, @collection, QueryMessage.new(@db.name, @collection.name, Query.new(sel)))
|
||||||
e = c.next_object
|
e = c.next_object
|
||||||
c.close
|
c.close
|
||||||
e
|
e
|
||||||
|
@ -173,7 +176,7 @@ module XGen
|
||||||
def refill_via_get_more
|
def refill_via_get_more
|
||||||
send_query_if_needed
|
send_query_if_needed
|
||||||
return if @cursor_id == 0
|
return if @cursor_id == 0
|
||||||
@db.send_to_db(GetMoreMessage.new(@db.name, @collection, @cursor_id))
|
@db.send_to_db(GetMoreMessage.new(@db.name, @collection.name, @cursor_id))
|
||||||
read_all
|
read_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ module XGen
|
||||||
def collections_info(coll_name=nil)
|
def collections_info(coll_name=nil)
|
||||||
selector = {}
|
selector = {}
|
||||||
selector[:name] = full_coll_name(coll_name) if coll_name
|
selector[:name] = full_coll_name(coll_name) if coll_name
|
||||||
query(SYSTEM_NAMESPACE_COLLECTION, Query.new(selector))
|
query(Collection.new(self, SYSTEM_NAMESPACE_COLLECTION), Query.new(selector))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a collection. If +strict+ is false, will return existing or
|
# Create a collection. If +strict+ is false, will return existing or
|
||||||
|
@ -182,8 +182,8 @@ module XGen
|
||||||
# Note that the query gets sent lazily; the cursor calls
|
# Note that the query gets sent lazily; the cursor calls
|
||||||
# #send_query_message when needed. If the caller never requests an
|
# #send_query_message when needed. If the caller never requests an
|
||||||
# object from the cursor, the query never gets sent.
|
# object from the cursor, the query never gets sent.
|
||||||
def query(collection_name, query)
|
def query(collection, query)
|
||||||
Cursor.new(self, collection_name, QueryMessage.new(@name, collection_name, query))
|
Cursor.new(self, collection, QueryMessage.new(@name, collection.name, query))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Used by a Cursor to lazily send the query to the database.
|
# Used by a Cursor to lazily send the query to the database.
|
||||||
|
@ -256,7 +256,7 @@ module XGen
|
||||||
# :ns :: Namespace; same as +collection_name+.
|
# :ns :: Namespace; same as +collection_name+.
|
||||||
def index_information(collection_name)
|
def index_information(collection_name)
|
||||||
sel = {:ns => full_coll_name(collection_name)}
|
sel = {:ns => full_coll_name(collection_name)}
|
||||||
query(SYSTEM_INDEX_COLLECTION, Query.new(sel)).collect { |row|
|
query(Collection.new(self, SYSTEM_INDEX_COLLECTION), Query.new(sel)).collect { |row|
|
||||||
h = {:name => row['name']}
|
h = {:name => row['name']}
|
||||||
raise "Name of index on return from db was nil. Coll = #{full_coll_name(collection_name)}" unless h[:name]
|
raise "Name of index on return from db was nil. Coll = #{full_coll_name(collection_name)}" unless h[:name]
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ module XGen
|
||||||
|
|
||||||
q = Query.new(selector)
|
q = Query.new(selector)
|
||||||
q.number_to_return = 1
|
q.number_to_return = 1
|
||||||
query(SYSTEM_COMMAND_COLLECTION, q).next_object
|
query(Collection.new(self, SYSTEM_COMMAND_COLLECTION), q).next_object
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue