-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathseed.js
More file actions
56 lines (48 loc) · 1.23 KB
/
Copy pathseed.js
File metadata and controls
56 lines (48 loc) · 1.23 KB
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
const {db, Vegetable, Gardener, Plot} = require('./models')
//store returned promise in var
let prom1 = Vegetable.create({
name: 'Carrot',
color: 'Orange',
planted_on: Date()
})
//store returned promise in var
let prom2 = Vegetable.create({
name: 'Tomato',
color: 'Red',
planted_on: Date()
})
//store returned promise in var
let prom3 = Vegetable.create({
name: 'Cucumber',
color: 'Green',
planted_on: Date()
})
//Promise.all runs promises in parallel
//call .then on promise.all to recieve an array like object of all promises passed
Promise.all([prom1, prom2, prom3]).then((arrVal) => {
//return arrVal actually creates data rows in our table
return arrVal
}).catch(console.log)
//dont forget to chain .catch to catch any errors that occured
db.sync({force: false})
.then(() => {
console.log('Successful, database sync')
db.close()
})
.catch((err) => {
console.log('Oops something went wrong...', err)
db.close()
})
// Chaining with .then() as opposed to using promise.all
// Runs prom
// Vegetable.create({
// name: 'Carrot',
// color: 'Orange',
// planted_on: Date()
// }).then((promise) => {
// return Vegetable.create({
// name: 'Tomato',
// color: 'Red',
// planted_on: Date()
// })
// }).then()