Using Sequelize: Setup & Basic Methods

전민식·2023년 1월 12일


목록 보기


What is Sequelize?

Let's see what the site says

ORM ELI5 : it is a magic box(library) that translates your code into one that can interact with the database.

Using Sequelize


  1. Install dependency
  2. In your datasource file, import and create new Sequelize with DBname, DBusername(root), DBpassword.. then export module

Connecting to DB

  1. In your server file(app.js/server,js..), import in the previously built module from the datasource file.
  2. use "sequelize.authenticate()" to connect
  3. Running server will log the success message.

Creating a Table

  1. Import sequelize & necessary modules
  2. Use sequelize.define() to create a table with desired columns

Query: basic CRUD

  1. findAll() :: SELECT * FROM posts
  2. create({id:1}) :: INSERT INTO posts(id) VALUES('1')
  3. update() :: UPDATE posts SET content = '...' WHERE '...'
  4. destroy() :: DELETE FROM posts WHERE id='1'
hi im minsik

0개의 댓글