Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async initialize () {
api.models = {}
const sequelizeInstance = new Sequelize(
api.config.sequelize.database,
api.config.sequelize.username,
api.config.sequelize.password,
api.config.sequelize
)
api.sequelize = {
sequelize: sequelizeInstance,
connect: async () => {
const dir = path.normalize(api.projectRoot + '/models')
fs.readdirSync(dir).forEach((file) => {
var nameParts = file.split('/')
var name = nameParts[(nameParts.length - 1)].split('.')[0]
api.models[name] = api.sequelize.sequelize.import(dir + '/' + file)
})
await api.sequelize.sequelize.sync()
},
disconnect: async () => {
await api.sequelize.sequelize.close()
}
fs.readdirSync(dir).forEach((file) => {
var nameParts = file.split('/')
var name = nameParts[(nameParts.length - 1)].split('.')[0]
api.models[name] = api.sequelize.sequelize.import(dir + '/' + file)
})
async stop () {
await api.sequelize.disconnect()
}
}