momi-foundation-coding / nodejs-api-cli

This is a scaffold for generating new API-based application for NodeJS and its frameworks such as Express, kemboijs, koa, AdonisJs etc.
http://www.kemboijs.org/
MIT License
10 stars 13 forks source link

improve some text info inside src/scripts/createdb.js #103

Closed ezkemboi closed 4 years ago

ezkemboi commented 4 years ago

Describe the bug Improve the following inside src/scripts/createdb.js

export default User.drop(() => {
  console.log('Successfully dropped db')
}).catch(error => {
  console.log('The Error', error)
})

To Reproduce

Expected behavior

export default User.drop(() => {
  console.log('Successfully dropped user table')
}).catch(error => {
  console.log('The Error', error)
})

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information): -N/A

Additional context N/A

ezkemboi commented 4 years ago

It also needs to make a modification to allow more than one export. In an app, it can have many tables.

ezkemboi commented 4 years ago

Since this is creating tables, we can run the function rather than exporting it. e.g

import { User } from '../models'

async function createTables() {
  // create a user table
  await User.sync().then(() => {
    console.log('Successfully created User table')
  }).catch(error => {
    console.log('The error: ', error)
  })
  // exit the process
  process.exit(0)
}

// run the function to create tables
createTables()

The command to create tables is npm run create:db.
Also, with such naming, naming change is required to be create-tables.js instead of createdb.js.