본문 바로가기

728x90

sequelize

sequelize raw query 간헐적 동작 안함 mysql에서 rownum 사용시 쿼리 결과가 나올 때 있고 안나올 때 있음 @rownum:=@rownum+1 rn 초기화를 where 절에서 하게되면 ex) WHERE (@rownum:=0)=0 으로 하게되면 seqeulize.query('SELECT @rownum:=@rownum+1 rn FROM prices WHERE (@rownum:=0)=0') 하면.. 결과가 나왔다 안나왔다 함... FROM 절에다가 선언하면 정상적으로 결과가 나옴 seqeulize.query('SELECT @rownum:=@rownum+1 rn FROM prices, (@rownum:=0)=0') temp) 이상~ 더보기
sequelize cli(migration) ■ 설치npm install --save sequelize-cli ■ initnode_modules/.bin/sequelize init==> .bin 폴더 하위에 config > config.jsonmigrationsmodels > index.js seeders 으로 생성됨 ■ Model Createsequelize model:generate --name User --attributes firstName:string,lastName:string,email:string models > users.js 생성됨migrations > timestamp-create-user.js 생성됨 ■ Migrationsequelize db:migrateUsers 테이블이 생성됨 ■ 활용방법sequelize migration.. 더보기
[ORM][Sequelize] include 모델에 order by 하기 참고한 내용https://github.com/sequelize/sequelize/issues/7510 Model.findAll({ include: [{ model: Nested, attributes: [] }], order: [[Nested, 'name', 'asc']] })A1.findone({where: { id: id },include: [ { model: B1, as: 'b1' } ],order: [ [ {model: B1, as: 'b1'}, 'createAt', 'DESC' ] ] A1.findone({where: { id: id },include: [ { model: B1, as: 'b1' } { model: C1, as: 'c1' } ],order: [ [ {model: B1, as: 'b.. 더보기

728x90