Skip to content

Commit

Permalink
Merge branch 'brettz9-multisegment-indexes'
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Apr 11, 2016
2 parents eca1b8f + 787ff22 commit 11b4b07
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 4 deletions.
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
- Validation: Tighter checking on argument to `modify` method (ensure is
an object) and on index creation objects (issue #149)
- Docs: Badges, CHANGES, clarify `add`, `update`, `delete`, `filter` and
`modify` methods and `schema` property behavior
`modify` methods, `schema` property behavior, and querying with ranges.
- Testing improvements: Travis/Karma/PhantomJS/Grunt (including allowing
override of Saucekey env var., overcoming PhantomJS issues with workers,
testing `versionchange` events in another window, testing bad args,
ensure Firefox is passing as well as Chrome)
testing array and nested `keyPath`'s and indexes, ensure Firefox is
passing as well as Chrome)

## 0.14.0 (March 8, 2016)

Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,40 @@ server.people.query('answer')
});
```

Note that IndexedDB allows you to use array keys within ranges (and
other methods where a key is accepted) as long as you have created
your store with an array `keyPath` (and optionally with an index
`keyPath`).

```js

// The definition:
schema: {
people: {
key: {
keyPath: ['lastName', 'firstName']
},
indexes: {
name: {
keyPath: ['lastName', 'firstName']
},
lastName: {},
firstName: {}
}
}
}

// ...elsewhere...

// The query:
s.test.query('name')
.only(['Zamir', 'Brett'])
.execute()
.then(function (results) {
// do something with the results
});
```

##### Limiting cursor range

Unlike key ranges which filter by the range of present values,
Expand Down
24 changes: 24 additions & 0 deletions tests/specs/bad-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@
done();
});
});
it('should catch when keyPath is an array and multiEntry=true', function (done) {
db.open({
server: this.dbName,
version: 2,
schema: {
test: {
key: {
keyPath: ['lastName', 'firstName']
},
indexes: {
name: {
keyPath: ['lastName', 'firstName'],
multiEntry: true
},
lastName: {},
firstName: {}
}
}
}
}).catch(function (err) {
expect(err.name).to.equal('InvalidAccessError');
done();
});
});
});

describe('open: createSchema', function () {
Expand Down
72 changes: 72 additions & 0 deletions tests/specs/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,78 @@
});
});

it('should allow defining (and querying) array keyPaths and multi-segment indexes', function (done) {
db.open({
server: this.dbName,
version: 1,
schema: {
test: {
key: {
keyPath: ['lastName', 'firstName']
},
indexes: {
name: {
keyPath: ['lastName', 'firstName']
},
lastName: {},
firstName: {}
}
}
}
}).then(function (s) {
s.test.add(
{lastName: 'Zamir', firstName: 'Brett'},
{lastName: 'Favre', firstName: 'Brett'},
{lastName: 'Brett', firstName: 'George'},
{lastName: 'Powell', firstName: 'Aaron'}
).then(function () {
return s.test.query()
.only(['Zamir', 'Brett'])
.execute();
}).then(function (results) {
expect(results[0].lastName).to.equal('Zamir');
expect(results.length).to.equal(1);
s.close();
done();
});
});
});

it('should allow defining (and querying) nested (dot-separated) keyPaths and indexes', function (done) {
db.open({
server: this.dbName,
version: 1,
schema: {
test: {
key: {
keyPath: 'person.name.lastName'
},
indexes: {
personName: {
keyPath: 'person.name.lastName'
}
}
}
}
}).then(function (s) {
s.test.add(
{person: {name: {lastName: 'Zamir', firstName: 'Brett'}}},
{person: {name: {lastName: 'Favre', firstName: 'Brett'}}},
{person: {name: {lastName: 'Brett', firstName: 'George'}}},
{person: {name: {lastName: 'Powell', firstName: 'Aaron'}}}
).then(function () {
return s.test.query('personName')
.only('Zamir')
.execute();
}).then(function (results) {
expect(results.length).to.equal(1);
expect(results[0].person.name.lastName).to.equal('Zamir');
s.close();
done();
});
});
});

it('should allow adding indexes to an existing object store', function (done) {
var spec = this;
db.open({
Expand Down
11 changes: 9 additions & 2 deletions tests/specs/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,14 @@
age: 40,
tags: ['one', 'two', 'three', 'four']
};
spec.server.add('test', item1, item2, item3).then(function () {
var item4 = {
id: 4,
firstName: 'Brett',
lastName: 'Zamir',
age: 43,
tags: ['two', 'three', 'four']
};
spec.server.add('test', item1, item2, item3, item4).then(function () {
done();
});
});
Expand Down Expand Up @@ -800,7 +807,7 @@
.all()
.execute()
.then(function (data) {
expect(data.length).to.equal(10);
expect(data.length).to.equal(13);
done();
});
});
Expand Down

0 comments on commit 11b4b07

Please sign in to comment.