Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koa 2.x #18

Open
kodermax opened this issue Jun 7, 2016 · 10 comments
Open

koa 2.x #18

kodermax opened this issue Jun 7, 2016 · 10 comments

Comments

@kodermax
Copy link

kodermax commented Jun 7, 2016

Give me please example for koa 2.x and koa-router 7.x

@danielmewes
Copy link
Member

@deontologician Do you know what it will take to update this example?

@deontologician
Copy link
Contributor

Not really. I think @segphault was saying koa 2.0 requires async/await, which aren't available in node yet. So you'd need to precompile with babel or something.

@segphault
Copy link

Koa 2 is still technically unreleased, pending the native availability of async/await in Node. More details about the status of Koa 2 here: koajs/koa#533

The status of async/await support in v8 is here: https://bugs.chromium.org/p/v8/issues/detail?id=4483

I don't think we want to replace our current Koa example with one that's based on 2.x until 2.x is official released, but I'm personally looking forward to building some demos with it myself when that eventually happens.

@kodermax
Copy link
Author

sadly :(

@danneu
Copy link

danneu commented Jun 10, 2016

I upgraded the koa example from koa 0.x to koa 1.x: #19. Baby steps!

@ralyodio
Copy link

ralyodio commented Jun 18, 2016

you can use koa2 with babel now. I'm wondering if the rethinkdb npm module will work with async/await

here's a simple example app -- if someone can show how to use async/await with rethinkdb that would be cool :) https://github.com/geekplux/koa2-boilerplate

@danneu
Copy link

danneu commented Jun 18, 2016

The move from koa1 to koa2 is so mechanically straightforward that koa2 is basically koa1 with build step boilerplate.

If you're wondering how to use rethinkdb with koa2, you could start with my koa1 example rewrite, introduce the build step from your linked boilerplate, change the old function * (next) signatures to async function (ctx, next), and bump the deps to ensure they are koa2 friendly: https://github.com/danneu/rethinkdb-example-nodejs/blob/7ac4ae718237db3e246faf719f5d41eed0fac568/todo-angular-koa/app.js.

If you're just suggesting that there be a koa2 example, then ignore me. Just trying to help. :)

@ralyodio
Copy link

ralyodio commented Jun 18, 2016

I figured it out last night. what you posted is helpful too.

router.get('/', async (ctx, next) => {
  ctx.body = await r.table('things').coerceTo('array').run(ctx.rdbConn);
});

@QasimQureshi
Copy link

@chovy Thanks! One quick question, did you change anything with the way rdbConn gets defined?

@ralyodio
Copy link

ralyodio commented May 6, 2017

I have something like this...but I am not sure if its the best way:

class Base {
  constructor(opts) {
    this.opts = opts;
    this.queries = [];
    this.r = r;
    this.conn = null;
  }

  async db() {
    this.conn = await this.r.connect({host: 'localhost', port: 28015, db: 'mydb'});
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants