My TypeScript Software Design & Architecture book just prelaunched! Check out solidbook.io.
Close

Active Record

Updated May 25th, 2019 / 1 min read

About this...

An `Active Record` is a model that stores an in-memory representation of a database row or document.




You know Sequelize, TypeORM, and Mongoose?

Those are all ORMs. When you return an instance of a row (or document), being able to make changes to the database row (that the instance references) is a popular usage of the Active Record pattern.

The Active Record patttern was initially documented by Martin Fowler

// Updating the 'name' column of a user using Sequelize.
const user = await User.find({ where: { user_id: 1 }});

await user.update({ name: 'Don Draper' });

Using instances of row objects returned from the ORM technology of our choice, we can Create, Read, Update and Delete instances of pretty much anything inside of the database.

Pretty cool!

0 Comments

Be the first to leave a comment

Submit