What is the Repository pattern in database integration?
The Repository pattern acts like a middleman between your app and the database. It helps organize data access code so your app talks to the repository instead of the database directly. This keeps code clean and easier to change later.
Click to reveal answer
intermediate
Explain the Unit of Work pattern.
Unit of Work groups multiple database operations into one single action. It makes sure all changes succeed or fail together, like a team working in sync. This helps keep data safe and consistent.
Click to reveal answer
intermediate
What is the Data Mapper pattern?
Data Mapper separates your app’s objects from the database structure. It moves data between objects and database tables without the objects knowing about the database. This keeps your app flexible and easier to test.
Click to reveal answer
beginner
How does the Active Record pattern work?
Active Record combines data and database actions in one object. Each object represents a row in the database and has methods to save, update, or delete itself. It’s simple but can mix business logic with database code.
Click to reveal answer
beginner
Why use connection pooling in database integration?
Connection pooling keeps a ready set of database connections open. When your app needs to talk to the database, it uses an existing connection instead of opening a new one. This makes your app faster and uses resources better.
Click to reveal answer
Which pattern groups multiple database changes to commit them all at once?
AUnit of Work
BRepository
CActive Record
DData Mapper
✗ Incorrect
Unit of Work ensures all database changes succeed or fail together as one transaction.
In which pattern does each object represent a database row and handle its own saving?
AData Mapper
BRepository
CActive Record
DUnit of Work
✗ Incorrect
Active Record objects combine data and database actions for each row.
What is the main benefit of using connection pooling?
AImproves app speed by reusing connections
BGroups database operations
CSeparates business logic from database code
DKeeps database schema flexible
✗ Incorrect
Connection pooling reuses open connections to reduce overhead and speed up database access.
Which pattern helps keep your app’s objects unaware of the database structure?
AActive Record
BRepository
CUnit of Work
DData Mapper
✗ Incorrect
Data Mapper moves data between objects and database tables without objects knowing about the database.
What role does the Repository pattern play?
AManages database transactions
BActs as a middleman for data access
CRepresents database rows as objects
DKeeps connections open
✗ Incorrect
Repository organizes data access code and acts as a middleman between app and database.
Describe the differences between Active Record and Data Mapper patterns.
Think about how tightly your app objects are connected to the database.
You got /4 concepts.
Explain why connection pooling improves database performance in web apps.
Imagine waiting in line vs having a shortcut to get served quickly.
You got /4 concepts.
Practice
(1/5)
1. In Remix, which function is primarily used to fetch data from a database before rendering a page?
easy
A. componentDidMount
B. action
C. useEffect
D. loader
Solution
Step 1: Understand Remix data fetching
Remix uses loader functions to fetch data on the server before rendering.
Step 2: Differentiate from actions and React lifecycle
action handles data updates, useEffect and componentDidMount are React client hooks, not Remix server loaders.
Final Answer:
loader -> Option D
Quick Check:
Data fetching = loader [OK]
Hint: Load data with loader, update with action [OK]
Common Mistakes:
Confusing loader with action
Using React hooks for server data fetching
Thinking componentDidMount runs on server
2. Which of the following is the correct syntax to export a loader function in a Remix route module?
B. function loader() { return fetchData(); } export default loader;
C. export default function loader() { return fetchData(); }
D. const loader = () => fetchData();
Solution
Step 1: Identify correct export style
Remix expects named exports for loaders, commonly as async arrow functions.
Step 2: Check each option
A uses default export, incorrect for Remix loaders; B declares function then exports as default, also incorrect; C exports named async arrow function, correct Remix pattern; D lacks export keyword.
D. Incorrect method db.user.create should be db.user.insert
Solution
Step 1: Check Remix imports
The redirect function must be imported from Remix to be used.
Step 2: Validate other code parts
formData.get is correct to get form values; redirect is synchronous; db.user.create is valid Prisma method.
Final Answer:
Missing import of redirect from Remix -> Option A
Quick Check:
Always import redirect before use [OK]
Hint: Check imports for Remix helpers like redirect [OK]
Common Mistakes:
Forgetting to import redirect
Confusing formData methods
Misnaming Prisma methods
5. You want to fetch a list of posts and their authors in a Remix loader using Prisma. Which pattern correctly fetches posts with author data included?
hard
A. await db.post.findMany({ select: { authorId: true } })
B. await db.post.findMany({ where: { author: true } })
C. await db.post.findMany({ include: { author: true } })
D. await db.post.findMany({ include: { authorId: true } })
Solution
Step 1: Understand Prisma include syntax
To fetch related data, use include with the related model name set to true.
Step 2: Evaluate each option
B correctly includes author data; A only selects authorId, not full author; C misuses where for inclusion; D tries to include a field, not a relation.