-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.js
67 lines (57 loc) · 1.23 KB
/
mysql.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Created by yatesmiao on 2017/8/6.
*/
const Sequelize = require('sequelize');
const config = require('./config');
const model = require('./model');
console.log('环境是', process.env.NODE_ENV)
let
Pet = model.Pet,
User = model.User;
var now = Date.now();
(async () => {
var dog = await Pet.create({
id: 'd-11111',
name: '苗苗',
gender: false,
birth: '2008-08-08'
});
console.log('创建了: ' + JSON.stringify(dog));
})();
(async () => {
var people = await User.create({
email: 'email--------->>>1111',
passwd: 'pass' + now.toString().split('').reverse().join(''),
name: '苗苗',
gender: true
});
console.log('创建了: ' + JSON.stringify(people));
})();
(async () => {
var pets = await Pet.update({
id: 'd-11111',
name: '苗苗',
gender: false,
birth: '2008-08-10'
},{
where: {
id: 'd-11111'
},
isNewRecord: true
});
console.log(`更新了 ${pets.length} pets:`);
for (let p of pets) {
console.log(JSON.stringify(p));
}
})();
(async () => {
var users = await User.findAll({
where: {
name: 'Odie'
}
});
console.log(`找到了 ${users.length} User:`);
for (let p of users) {
console.log(JSON.stringify(p));
}
})();