DEV Community

Discussion on: A crash course on Serverless with AWS - Building APIs with Lambda and Aurora Serverless

Collapse
 
adnanrahic profile image
Adnan Rahić

Add another model to the object.
In db.js:

const Models = { Note, User }

Once you want to require the models in the handler.js you can choose which one you want.

const { Note } = await connectToDatabase()
// or
const { User } = await connectToDatabase()
// or even
const { Note, User } = await connectToDatabase()

It's up to you to use what you like more. I personally think destructuring is freaking awesome. :)

Collapse
 
christiams profile image
Christian Carrillo

What do you mean with destructuring?

Thread Thread
 
kayis profile image
K
Collapse
 
bryangerre profile image
BryanGerre

Thanks so much, I'll try the above. thanks again

Collapse
 
bryangerre profile image
BryanGerre • Edited

Last question, what would be the best way to associate those two tables? I've found many examples, but it would require a refactoring of the model's .js file.