Comments (4)
Sure. The query() portion is likely what you are looking for.
$indexedDB.openStore("foo", function (fooStore) {
query = fooStore.query();
query.findWhere(query.$index("id").$lt(5)).then( function (limitedObjects) {
... do some stuff with the items...
});
});
See https://github.com/bramski/angular-indexedDB/blob/master/angular-indexed-db.js#L660
for a bit more info on the "query" object and what you can do with it. Internally the cursor is used to iterate and return your results for most things. Implementing a pageable result should be fairly trivial.
from angular-indexeddb.
Hi bramski,
thank you for your reply. I try your code and it works well except for the line 3 where query.findWhere should be fooStore.findWhere. So the snippet is:
$indexedDB.openStore("foo", function (fooStore) {
query = fooStore.query();
store.findWhere(query.$index("id").$lt(5)).then( function (limitedObjects) {
//do some stuff with the items...
});
});
Overall this solution works well for an index that works like a sql sequence but suppose you have and index for a property like "name", I would like to use the library in order to retrieve the top 5 results and not the records with the property "name" between "a" and "b". With the IDBCursor I could use the advance() function [http://www.w3.org/TR/IndexedDB/#widl-IDBCursor-advance-void-unsigned-long-count].
I'll try to modify the code.
Best regards
from angular-indexeddb.
Right now the library does not give you access to the "continue" function of the cursor and to do essentially a "limit". I don't see that as particularly difficult but it would have to be implemented in the internals of the library.
You are welcome to fork and work on this change if it is something you need. Below is a link to the function you would need to work with to make this happen. Right now what occurs is that a "cursor" is opened and it is simply iterated until exhaustion. You could simply provide a "limit" to reduce your number of results.
https://github.com/bramski/angular-indexedDB/blob/master/src/angular-indexed-db.coffee#L217
Typically a paging solution needs an "offset" though so a proper limit would have to use a known value to begin the query from.
Cheers!
from angular-indexeddb.
Closing this. Feel free to re open if your question isn't addressed.
from angular-indexeddb.
Related Issues (20)
- Adds then retrieves first time. Can't retrieve second time HOT 3
- not able to get error log HOT 2
- Upgrade function ordering HOT 1
- logs in code HOT 3
- Wrong usage of @defer.reject() HOT 6
- Unnecessary runtime bower dependency HOT 1
- Is querying over multi entry indexes implemented? HOT 4
- Extremely slow calling table.getAll() in IE (11) HOT 9
- t text to bianry HOT 1
- Unable to install HOT 2
- Additional Maintainers Needed
- Not able to use $indexedDB, $indexedDBProvider in angular service HOT 1
- How can i check if a data sore is exist to insert in it and if isn't create new one?
- i need a function to call it for creating new data store? HOT 1
- How can i get existing data store names...Please? HOT 1
- Unable to store an array of objects corresponding to one key HOT 1
- A) READ THIS BEFORE YOU CREATE AN ISSUE
- Detect failure at the time of opening the store HOT 4
- getAll with limits HOT 2
- Difference between .getAll() and .each()? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-indexeddb.