0
0
Expressframework~10 mins

Sequelize ORM setup in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import Sequelize from the package.

Express
const { [1] } = require('sequelize');
Drag options to blanks, or click blank then click option'
Asequelize
BSequelize
CSequelizer
DSeq
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'sequelize' instead of 'Sequelize'.
Misspelling the import name.
2fill in blank
medium

Complete the code to create a new Sequelize instance connecting to a SQLite database.

Express
const sequelize = new Sequelize({ dialect: 'sqlite', storage: [1] });
Drag options to blanks, or click blank then click option'
A'sqlite.db'
B'memory'
C'database.sqlite'
D'db.sqlite3'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'memory' which is not a valid file path.
Using a file name without quotes.
3fill in blank
hard

Fix the error in the code to authenticate the Sequelize connection.

Express
async function testConnection() {
  try {
    await sequelize.[1]();
    console.log('Connection successful');
  } catch (error) {
    console.error('Connection failed:', error);
  }
}
Drag options to blanks, or click blank then click option'
Aauthenticate
BtestConnection
CconnectDB
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'connect' which is not a Sequelize method.
Calling a non-existent method like 'connectDB'.
4fill in blank
hard

Fill both blanks to define a Sequelize model named 'User' with a string 'username' field.

Express
const User = sequelize.[1]('User', {
  username: {
    type: DataTypes.[2],
    allowNull: false
  }
});
Drag options to blanks, or click blank then click option'
Adefine
BSTRING
CINTEGER
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' instead of 'define' to make a model.
Using 'INTEGER' for a username field.
5fill in blank
hard

Fill all three blanks to sync the database and handle success or error.

Express
sequelize.[1]()
  .then(() => {
    console.log('[2] synced successfully');
  })
  .catch(([3]) => {
    console.error('Sync failed:', [3]);
  });
Drag options to blanks, or click blank then click option'
Async
BDatabase
Cerror
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'connect' instead of 'sync'.
Naming the error parameter incorrectly.