Skip to content

Commit

Permalink
add a regex matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Mar 14, 2016
1 parent d0454b9 commit 46d3503
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/finding_data.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The search object can take a few forms depending on what you want to find:
{name: 'kevin'} // Will be expanded to is (see next line)
{name: {is: 'kevin'}} // name is kevin
{name: {isnot: 'kevin'}} // name is not kevin
{name: {matches: /kev/}} // name matches the pattern /kev/
{height: {gt: 100}} // height is greater than 100
{height: {lt: 90}} // height is less than 90
{eyes: {is: [1, 2]}} // eyes is 1 OR 2
Expand Down
4 changes: 4 additions & 0 deletions src/compares.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ module.exports =
includes: (field, value, objects) ->
objects.filter (entry) ->
(entry[field].indexOf(value) != -1)

matches: (field, value, objects) ->
objects.filter (entry) ->
(value.test entry[field])
4 changes: 4 additions & 0 deletions tests/sodb-tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ for caching in [true, false]
results = db.where({likes: {includes: 'bananas'}})
expect(results.length).to.equal 4

it 'should support matches', ->
results = db.where({name: {matches: /kev/}})
expect(results.length).to.equal 1

describe 'result manipulation', ->
it 'should order by', ->
ordered = db.order({name: {isnot: 'something new'}}, "age")
Expand Down

0 comments on commit 46d3503

Please sign in to comment.