Move the :fields find() parameter into the options hash.
This commit is contained in:
parent
cfee63194c
commit
6ab2f77eb7
3
README
3
README
|
@ -54,9 +54,6 @@ type
|
|||
|
||||
* Implement Babble's algorithm for ObjectID. Implement Comparable.
|
||||
|
||||
* Change find(selector={}, fields=nil, options={}) to find(selector={},
|
||||
options={})
|
||||
|
||||
* ObjectID equality.
|
||||
|
||||
* Capped collection support.
|
||||
|
|
|
@ -26,7 +26,14 @@ module XGen
|
|||
@name = name
|
||||
end
|
||||
|
||||
def find(selector={}, fields=nil, options={})
|
||||
# Options:
|
||||
# * <tt>:fields</tt> - Array of collection field names; only those will be returned (plus _id if defined)
|
||||
# * <tt>:offset</tt> - Start at this record when returning records
|
||||
# * <tt>:limit</tt> - Maximum number of records to return
|
||||
# * <tt>:sort</tt> - Hash of field names as keys and 1/-1 as values; 1 == ascending, -1 == descending
|
||||
# <tt>
|
||||
def find(selector={}, options={})
|
||||
fields = options.delete(:fields)
|
||||
fields = nil if fields && fields.empty?
|
||||
@db.query(@name, Query.new(selector, fields, options[:offset] || 0, options[:limit] || 0, options[:sort]))
|
||||
end
|
||||
|
|
|
@ -99,7 +99,7 @@ class DBAPITest < Test::Unit::TestCase
|
|||
|
||||
def test_array
|
||||
@coll << {'b' => [1, 2, 3]}
|
||||
rows = @coll.find({}, {'b' => 1}).collect
|
||||
rows = @coll.find({}, {:fields => ['b']}).collect
|
||||
assert_equal 1, rows.length
|
||||
assert_equal [1, 2, 3], rows[0]['b']
|
||||
end
|
||||
|
@ -107,7 +107,7 @@ class DBAPITest < Test::Unit::TestCase
|
|||
def test_regex
|
||||
regex = /foobar/i
|
||||
@coll << {'b' => regex}
|
||||
rows = @coll.find({}, {'b' => 1}).collect
|
||||
rows = @coll.find({}, {:fields => ['b']}).collect
|
||||
assert_equal 1, rows.length
|
||||
assert_equal regex, rows[0]['b']
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue