Sequelize Common Operation Demo
Link
var sequelize = require (' sequelize ');
var sequelize = new Sequelize (' Nodejs ', ' root ', ', ', {host: ' 127.0.0.1 ', Port: ' 3306 ', dialect: ' MySQL '});
Inquire
Task.findall ({limit:10, Age:{gt:3},order: ' ID ASC '}, {raw:true, logging:true, Plain:false}). On (' Success ', functio N (res) {
console.log (res);
}). On (' Failure ', function (err) {
console.log (err);
})
Statistics
Task.count ({where: {title: ' Test_title_1 '}}, {Logging:false}). On (' Success ', function (i) {
console.log (i);
}) . On (' Failure ', function (err) {
console.log (err);
});
Maximum or minimum
Task.max (' id '). On (' Success ', function (max) {
console.log (max);
}). On (' Failure ', function (err) {
console.log (err);
});
Insert
Task.build ({title: ' Test_title_3 ', ' description ': ' Test_description_3 '}). Save (). On (' Success ', function (msg) {
Console.log (msg);
}). On (' Failure ', function (err) {
console.log (err);
});
Task.create ({title: ' Test_title_4 ', ' description ': ' Test_description_4 '}). On (' Success ', function (msg) {
Console.log (msg);
}). On (' Failure ', function (err) {
console.log (err);
});
Modify
Task.update ({description: ' test_description_2000 '}, {id: ' 2 '}). On (' Success ', function (msg) {
console.log (msg);
}). On (' Failure ', function (err) {
console.log (err);
});
Delete
Task.destroy ({ID: ' 4 '}). On (' Success ', function (msg) {
console.log (msg);
}). On (' Failure ', function (err) {
console.log (err);
});
Thank you for reading, I hope to help you, thank you for your support for this site!