0
0
Expressframework~20 mins

Sequelize ORM setup in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sequelize ORM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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
  }
});
AA column named 'age' with string type that cannot be null
BA column named 'age' with integer type that can be null
CA column named 'age' with boolean type that can be null
DA column named 'age' with date type that cannot be null
Attempts:
2 left
💡 Hint
Look at the 'type' and 'allowNull' properties in the model definition.
📝 Syntax
intermediate
2: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?
Aconst sequelize = new Sequelize('sqlite', 'memory');
Bconst sequelize = new Sequelize('sqlite::memory:');
Cconst sequelize = new Sequelize({ dialect: 'sqlite', storage: ':memory:' });
Dconst sequelize = new Sequelize('sqlite://memory');
Attempts:
2 left
💡 Hint
Check the Sequelize docs for SQLite connection strings.
🔧 Debug
advanced
2: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();
ABecause 'await' cannot be used outside async functions
BBecause 'sync' is not a method on Sequelize instances
CBecause SQLite is not supported by Sequelize
DBecause Sequelize must be called with 'new' keyword to create an instance
Attempts:
2 left
💡 Hint
Check how Sequelize instances are created.
state_output
advanced
2: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);
})();
A1
Bundefined
Cnull
DThrows an error because 'id' is not defined
Attempts:
2 left
💡 Hint
Sequelize auto-generates primary keys named 'id' by default.
🧠 Conceptual
expert
2:00remaining
Which option best describes Sequelize's 'sync' method behavior?
What does calling sequelize.sync({ force: true }) do in a Sequelize setup?
AOnly creates tables if they do not exist, without dropping anything
BUpdates existing tables without dropping them
CDrops all tables and recreates them according to model definitions
DDeletes all data from tables but keeps the structure intact
Attempts:
2 left
💡 Hint
Check the meaning of 'force' in Sequelize sync options.