Skip to content

Instantly share code, notes, and snippets.

@shramee
Created November 1, 2021 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shramee/1be306a8eb626810fd46f78ca57e3d37 to your computer and use it in GitHub Desktop.
Save shramee/1be306a8eb626810fd46f78ca57e3d37 to your computer and use it in GitHub Desktop.
Resets the database for NTU SDI vehicles and driver database
async function addDataToDB() {
try {
// Destructive operation do only when needed
// await sequelize.sync( {force: true} );
await Vehicle.create( {
type: 'car',
carPlateNo: 'SA882'
} );
await Vehicle.create( {
type: 'car',
carPlateNo: 'SP558',
driverId: 1,
} );
await Driver.create( {
carLicenseNo: '25990234',
fullName: 'Shramee Srivastav',
} );
await Driver.create( {
carLicenseNo: '25990235',
fullName: 'John Doe',
} );
await Driver.create( {
carLicenseNo: '25990224',
fullName: 'Jane Doe',
} );
// Fetch all data Vehicle.findAll
const vehiclesInDB = await Vehicle.findAll();
vehiclesInDB.forEach( v => console.log( v.id + ' ' + v.type ) );
const driversInDB = await Driver.findAll();
driversInDB.forEach( d => console.log( d.id + ' ' + d.fullName ) );
} catch ( err ) {
console.log( err );
}
}
// Do this when needed
// addDataToDB();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment