I don’t know about you guys, but I always have an annoying time trying to figure out how to make Sequelize work — the documentation seems to have a dearth of examples. Here’s a few examples for “common” functionality.

Get plain objects instead of Sequelize Instances after bulkCreate

models.Item.bulkCreate(values)  
.then(results => results.map(result => result.get({ plain: true }))) // Convert to plain
.then(items => console.log(items)) // Plain object array [{...}, {...}, ...]

Pretty easy, use .get({ plain: true }) on any Sequelize instance to convert it to a plain JavaScript object.

Sequelize bulkCreate but ignore any duplicates

models.Item.bulkCreate(values, {  
    ignoreDuplicates: true 
})

Just use the ignoreDuplicates option and pass it as the second argument.

Deleting a row

Delete is called destroy, use it as so:

models.Items.destroy({  
    where: {
        id: 42
    }
})
Namanyay Goel

Hey, thanks for reading so far!

Hi there, I’m Namanyay. I've consulted startups on building great products for over ten years. I write about technology, startups, and AI, often on X.

I recently moved to San Francisco to help developers ship faster & write higher quality code. My tool is used by thousands, including engineers from Google and Uber. Learn more about Giga AI.

If you enjoyed this post, please consider sharing it with your friends and colleagues. Your support motivates me: