You should be able to:
- Define an ORM, and explain its pros/cons
- Define models in Sequelize
- Associate models with each other
- Hook into Sequelize lifecycle events
- Query on models (
findAll
,findOne
,create
, "magic methods", etc)
Option | Explanation | |
---|---|---|
☑️ | A type of ORM | |
A type of database | It just helps us connect to a database. It's not the database itself. |
|
☑️ | A library that converts between tables/rows and classes/instances | |
☑️ | Used in Node applications to connect to SQL databases | |
Used in Node applications to connect to ANY type of database | For NoSQL DBs such as Document Store (MongoDB), we would need to use a ODM (Object Data Modeling). In the case of MongoDB, the equivalent would be Mongoose. |
The model should be defined, the name attribute should not be allowed to be null, its type should be a text type and pictureURL should be a string type.
const User = db._____('user', {
name: {
type: Sequelize._____,
_____: false
},
pictureUrl: _____.TEXT
})
define
,STRING
,allowNull
,Sequelize
☑️const User = db.define('user', { name: { type: Sequelize.STRING, allowNull: false }, pictureUrl: Sequelize.TEXT })
Sequelize
,TEXT
,isNotEmpty
,define
define
,TEXT
,isNotNull
,Sequelize
define
,STRING
,allowNull
,global
A journal app has three entities, Author, Entry and Tag. There is a one-to-one relationship between Author and Pseudonym, a one-to-many relationship between Author and Entry and a many-to-many relationship between Tag and Entry. Choose the correct method for these relationships below.
hasOne |
hasMany |
belongsToMany |
|
---|---|---|---|
Author to Entry | ☑️ | ||
Author to Pseudonym | ☑️ | ||
Entry to Tag | ☑️ |
beforeValidate
,afterDestroy
,beforeCreate
afterCreate
,beforeDestroy
,beforeValidate
beforeValidate
,afterValidate
,beforeCreate
☑️beforeDestroy
,beforeCreate
,beforeValidate
,afterUpdate
Extra resources:
- Julissa's Hooks and Ops Gist
- Sequelize: Hooks (official documentation)
findAll
findOne
☑️create