Challenge - 5 Problems
Sequelize ORM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Sequelize model definition produce?
Consider this Sequelize model definition for a User. What will be the data type of the 'age' column in the database?
Express
const User = sequelize.define('User', { name: { type: Sequelize.STRING, allowNull: false }, age: { type: Sequelize.INTEGER, allowNull: true } });
Attempts:
2 left
💡 Hint
Look at the 'type' and 'allowNull' properties in the model definition.
✗ Incorrect
The 'age' field is defined with Sequelize.INTEGER and allowNull: true, so it creates an integer column that can be null.
📝 Syntax
intermediate2:00remaining
Which option correctly initializes Sequelize with SQLite?
You want to create a Sequelize instance using SQLite as the database. Which code snippet correctly does this?
Attempts:
2 left
💡 Hint
Check the Sequelize docs for SQLite connection strings.
✗ Incorrect
The correct ways to initialize Sequelize with an in-memory SQLite database are using the connection string 'sqlite::memory:' or the object with dialect and storage.
🔧 Debug
advanced2:00remaining
Why does this Sequelize sync code throw an error?
Given this code snippet, why does calling sequelize.sync() throw a TypeError?
Express
import { Sequelize } from 'sequelize'; const sequelize = Sequelize('sqlite::memory:'); await sequelize.sync();
Attempts:
2 left
💡 Hint
Check how Sequelize instances are created.
✗ Incorrect
Sequelize is a class and must be instantiated with 'new'. Calling Sequelize() without 'new' returns undefined, causing sync() to fail.
❓ state_output
advanced2:00remaining
What is the output after creating and saving a User instance?
Given this code, what will be logged to the console?
Express
const { Sequelize, DataTypes } = require('sequelize');
const sequelize = new Sequelize('sqlite::memory:');
const User = sequelize.define('User', {
username: DataTypes.STRING
});
(async () => {
await sequelize.sync();
const user = User.build({ username: 'alice' });
await user.save();
console.log(user.id);
})();Attempts:
2 left
💡 Hint
Sequelize auto-generates primary keys named 'id' by default.
✗ Incorrect
After saving, Sequelize assigns an auto-incremented 'id' starting at 1 to the instance.
🧠 Conceptual
expert2:00remaining
Which option best describes Sequelize's 'sync' method behavior?
What does calling sequelize.sync({ force: true }) do in a Sequelize setup?
Attempts:
2 left
💡 Hint
Check the meaning of 'force' in Sequelize sync options.
✗ Incorrect
Using 'force: true' drops all tables and recreates them fresh, which deletes all data.