Giter Club home page Giter Club logo

Comments (4)

bramski avatar bramski commented on July 23, 2024

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.

capitanfuturo avatar capitanfuturo commented on July 23, 2024

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.

bramski avatar bramski commented on July 23, 2024

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.

bramski avatar bramski commented on July 23, 2024

Closing this. Feel free to re open if your question isn't addressed.

from angular-indexeddb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.