Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Using SQL ORMs with Node.js Getting Started with Sequelize Test the Database

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

How do we store pictures or any other files in the database?

Can we store files as well in the database or do we need NoSql database for that?

Caleb Kemp
Caleb Kemp
12,755 Points

Well, a VARCHAR is a native SQL data type that stores a variable-length sequence of characters with the last two bytes giving its size. I.E, "JEN" would be stored using 5 bytes, one for each character and 2 for the length. VARCHAR is usually preferable over the CHAR type unless the data is all the same size and short in length. So VARCHAR(250), 250 is the maximum number of characters it will store in a single entry. What is String (500)? String is NOT part of the SQL syntax but is a function used by Sequelize ORM to handle the VARCHAR data type. If you were to write just Sequelize.STRING it will create a VARCHAR(255) (if no size given).

So STRING (500) would create a VARCHAR (500) in the database. Here are some of the common sequelize data types, and here is the Sequelize documentation covering the String type. Hope that helps :grinning:

1 Answer

Caleb Kemp
Caleb Kemp
12,755 Points

Although you can store images, videos, and the like directly in the database using the "Blob" and "varbinary" fields, it is not recommended. Usually, the image or file will get stored on the server in a resources folder and you will just store the link or pointer to it on the database itself.