GithubHelp home page GithubHelp logo

Comments (2)

GregBrimble avatar GregBrimble commented on July 16, 2024 1

Hi @CrockAgile ,

I'm not affiliated with this workers-types, but in my own projects, I've been using something like this, which might be of use to you:

async function* listAll(namespace, options) {
  let cursor;
  let hasNextPage = true;
  while (hasNextPage) {
    const results = await namespace.list({ ...options, cursor })
    const { keys: queue } = results
    hasNextPage = !results.list_complete

    while (queue.length > 0) {
      const key = queue.shift()
      if (key !== undefined) yield key
    }
  }
}

Which then allows you to use a for await...of loop in an async function:

for await (const key of listAll(NAMESPACE, {"prefix": "user:1:" })) {
  // use key
  // e.g. await NAMESPACE.get(key.name)
}

As an unrelated aside, your key generation looks very similar to that of my own project's kv-orm. I'd be very interested to hear about what you're working on, if kv-orm could be of any use, and/or if I could learn anything from what you're working on. My email is in my profile. Please get in touch!

from workers-types.

CrockAgile avatar CrockAgile commented on July 16, 2024 1

Thanks for the example @GregBrimble ! Glad to know I am not the only one hitting this use case. I'm not working on anything interesting. I am building a minimal app just to learn my way around CF workers. I'll give kv-orm a look since it seems to be a more full feature version of the hacky data model I am using for this small test project.

from workers-types.

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.