DEV Community

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

Collapse
 
bryangerre profile image
BryanGerre

Hey Adnan. Thank you so much for taking the time to develop this example. How would you introduce another model to this solution? Set's say I wanted to add UsersModel. I've created the users.js within the models directory. the db.js you have only passes in one model ( const Models = { Note }) could that be an array of models? const Models = [Note, User, etc]? If so how does the handler.js know which model?

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.