-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path6_DeleteOperation.js
42 lines (38 loc) · 1.01 KB
/
6_DeleteOperation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Including dependency
var Sequelize = require("sequelize");
//Setting up the config
var sequelize = new Sequelize('your-database', 'db-usernaem', 'db-password', {
host: "localhost",
port: 3306,
dialect: 'mysql'
});
//Checking connection status
sequelize.authenticate().complete(function (err) {
if (err) {
console.log('There is connection ERROR');
} else {
console.log('Connection has been established successfully');
}
});
//Create Item Table Structure
var Item = sequelize.define('Item', {
id: Sequelize.STRING,
name: Sequelize.STRING,
description: Sequelize.STRING,
qty: Sequelize.INTEGER
});
//Delete All Computer Records
Item.find({where: {name: 'Computer'}}).complete(function (err, data) {
if (err) {
console.log(err);
} else {
data.destroy({}).success(function (err, data) {
if(err){
console.log(err);
}else{
console.log(data);
}
})
}
console.log(data);
});