Showing posts with label sequelize. Show all posts
Showing posts with label sequelize. Show all posts

Tuesday, December 3, 2019

Node.js sequelize MySQL JSON function 사용하기

select * from actionlog where JSON_EXTRACT(action, '$name')='reward'

const actionLogs: ActionLog[] = await ActionLog.findAll({
    where: Sequelize.where(
        Sequelize.fn('JSON_EXTRACT',
            Sequelize.col('action'),
            '$.name'),
        'reward')
})

Monday, September 16, 2019

MySQL timezone setting in Node.js sequelize

Saturday, October 27, 2018

Node.js sequelize async로 sync하기

sequelize를 프로그램 시작시에 sync하기 위해서는 sequelize.sync()를 호출해줘야 하는데 이것은 Promise<any>를 리턴하여 바로 다음줄에 DB작업을 하기 위해서는 에러가 날 위험이 있다.

따라서 다음과 같이 async/await으로 변경하면 위험을 막을 수 있다.
async function sync() {
  console.log('sync begin')
  await sequelize.sync();
  console.log('sync end')
  // all tables created
}

sync();