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

Cannot Access the db in handlers? #15

Closed
zzzet opened this issue May 17, 2016 · 3 comments
Closed

Cannot Access the db in handlers? #15

zzzet opened this issue May 17, 2016 · 3 comments

Comments

@zzzet
Copy link

zzzet commented May 17, 2016

Here is the dbConneciton:

const Sqlite3 = require('sqlite3');

const db = new Sqlite3.Database('./dindin.sqlite');

I had use bind the db with server.bind({ db: dbConnection }) but i dont know why i cannot access the this.db in handlers. According to book [Hapi Js in Action] and server.bind it should be working. I had to use server.app.db = dbConnection and every handler i had to do something like const db = request.server.app.db and works fine.. is there issue with server.bind in hapi js version 13.4.0 and I m loving ur book....

@mtharrison
Copy link
Owner

mtharrison commented May 17, 2016

Which chapter/subsection are you working on? Is it chapter 2? There's a full example from that chapter here, it's working ok for me with hapi 13.4.0.

https://github.com/mtharrison/hapi.js-in-action/tree/master/CH02%20-%20Building%20an%20API/2.6/2.6.2

Perhaps you can compare that to your code. If you still have trouble, try to post more code here and I can help.

@zzzet
Copy link
Author

zzzet commented May 19, 2016

i got it working with server.app.db = dbConnection but not with server.bind({db: dbConnection }).. May be there is issue with my code.. I will compare it.

But is it ok if i use server.app.db too ?

@mtharrison
Copy link
Owner

Yes server.app.db works too.

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

2 participants