Sequelize 시퀄라이즈 참고

Robin·2022년 11월 25일
0

TIL

목록 보기
19/24
post-custom-banner

참고

Terminology convention

  • Sequelize: 라이브러리 그 자체 일컫는다
  • sequelize: instance of Sequelize, which represents a connection to one database

Promises and async/await

Most of the methods provided by Sequelize are asynchronous and therefore return Promises. They are all Promises , so you can use the Promise API (for example, using then, catch, finally) out of the box.
Of course, using async and await works normally as well.

Model

  • Usually, models have singular names (such as User) while tables have pluralized names (such as Users), although this is fully configurable.

Model 만드는 2가지 방법
1. sequelize.define()
2. Model.init

Internally, sequelize.define calls Model.init, so both approaches are essentially equivalent.

Model에서 사용될 수 있는 API

DataTypes

DataTypes.STRING             // VARCHAR(255)
DataTypes.STRING(1234)       // VARCHAR(1234)
DataTypes.STRING.BINARY      // VARCHAR BINARY
DataTypes.TEXT               // TEXT
DataTypes.TEXT('tiny')       // TINYTEXT
DataTypes.CITEXT             // CITEXT          PostgreSQL and SQLite only.
DataTypes.TSVECTOR           // TSVECTOR        PostgreSQL only.

// 이외에도 다수 있으니 문서 확인
profile
Always coding or dog walking
post-custom-banner

0개의 댓글