Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Why is a repository method like `userRepository.query("SELECT * FROM users")` considered an anti-pattern?
💻 Code Challenge | +75 XP
Define a UserRepository interface with findById, findActive, and save methods, implement it with a Sequelize-backed class, and implement a second in-memory version suitable for fast unit tests.
A business logic function is difficult to unit test because it calls User.findAll() directly from an ORM. Reorder the steps to decouple it using the repository pattern.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Exposing a generic query() method or accepting raw ORM query objects through the repository interface
// Wrong: leaks the abstraction right back out
userRepository.query("SELECT * FROM users WHERE active = ?", [true]);
// Correct: domain-meaningful, opaque to the caller
userRepository.findActive();The Solution //
This leaks the underlying database/ORM abstraction right back through the interface that was supposed to hide it, defeating the entire purpose of introducing a repository. A well-designed repository exposes only domain-meaningful, specific methods like findActive() or findByEmail(), never a generic pass-through for arbitrary queries.
The Error //
Scattering direct ORM calls (User.findAll(), etc.) throughout business logic instead of behind a repository
// Wrong: business logic tightly coupled to Sequelize directly
async function getVipCustomers() {
return User.findAll({ where: { tier: "vip" } }); // Sequelize-specific
}
// Correct: depends on the repository abstraction
async function getVipCustomers(userRepository) {
return userRepository.findByTier("vip");
}The Solution //
This tightly couples business logic to a specific ORM and its query API, making the logic hard to unit test in isolation and hard to migrate if the persistence technology ever changes. Introduce a repository interface and have business logic depend on it instead of the ORM directly.