Skip to content

Commit

Permalink
fix index returning undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Jul 4, 2017
1 parent 2d4115b commit 26adc90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sodb",
"version": "1.2.4",
"version": "1.2.5",
"description": "Single Object Database",
"main": "lib/sodb.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/sodb.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ module.exports =
@where.apply(this, arguments)[0]

indexLookup: (key) ->
return @unref @objects[@index[key]]
if @objects[@index[key]]
return @unref @objects[@index[key]]
else
return undefined

#
# unref(entry)
Expand Down
9 changes: 9 additions & 0 deletions tests/sodb-tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ for caching in [true, false]

expect(result.age).to.equal 10

it 'should return undefined if no lookup exists', ->
tdb = new sodb({index: 'name'})

tdb.add({name: 'dave', age: 10})

result = tdb.indexLookup('phil')

expect(result).to.equal undefined

describe 'compares', ->
it 'should support greater than', ->
results = db.where({eyes: 2}, {age: {gt: 25}})
Expand Down

0 comments on commit 26adc90

Please sign in to comment.