Sails.js Tutorial : 모델 생성
xyz/config/models.js
아래 2라인을 찾아서 주석을 해제하고, migrate는 drop 으로 변경한다.... connection: 'localDiskDb', migrate: 'drop', ...
- Admin 모델(
xyz/api/models/Admin.js
)을 생성한다.// Admin.js module.exports = { tableName: 'tb_admin', attributes: { userid: { type: 'string', unique: true }, password: { type: 'string', required: true }, nick: { type: 'string', unique: true } }, autoUpdatedAt: false, autoCreatedAt: false, }
config/bootstrap.js
초기값을 넣는다.module.exports.bootstrap = function(cb) { Admin.create({userid: 'userid1', password: 'pass1', nick: '길동'}).exec(console.log); Admin.create({userid: 'userid2', password: 'pass2', nick: '정호'}).exec(console.log); Admin.create({userid: 'userid3', password: 'pass3', nick: '성장'}).exec(console.log); Admin.create({userid: 'userid4', password: 'pass4', nick: '상욱'}).exec(console.log); Admin.create({userid: 'userid5', password: 'pass5', nick: '동영'}).exec(console.log); // It's very important to trigger this callback method when you are finished // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) cb(); };
- 프로젝트가 실행되면서, 초기값이 DB에 입력되는 것을 확인할 수 있다.
$ cd xyz $ sails lift info: Starting app... info: info: .-..-. info: info: Sails <| .-..-. info: v0.12.9 |\ info: /|.\ info: / || \ info: ,' |' \ info: .-'.-==|/_--' info: `--'-------' info: __---___--___---___--___---___--___ info: ____---___--___---___--___---___--___-__ info: info: Server lifted in `C:\Mattabu\Study\Node\xyz` info: To see your app, visit http://localhost:1337 info: To shut down Sails, press <CTRL> + C at any time. debug: ------------------------------------------------------- debug: :: Tue Nov 08 2016 15:54:36 GMT+0900 (대한민국 표준시) debug: Environment : development debug: Port : 1337 debug: ------------------------------------------------------- null { userid: 'userid1', password: 'pass1', nick: '길동', id: 5 } null { userid: 'userid2', password: 'pass2', nick: '정호', id: 6 } null { userid: 'userid3', password: 'pass3', nick: '성장', id: 7 } null { userid: 'userid4', password: 'pass4', nick: '상욱', id: 8 } null { userid: 'userid5', password: 'pass5', nick: '동영', id: 9 }
댓글
댓글 쓰기