-
Notifications
You must be signed in to change notification settings - Fork 317
/
seed.js
71 lines (67 loc) · 2.09 KB
/
seed.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
68
69
70
71
// This file allows us to seed our application with data
// simply run: `node seed.js` from the root of this project folder.
var db = require('./models');
var books_list = [
{
title: "To Kill a Mockingbird",
author: "Harper Lee",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/to_kill_a_mockingbird.jpg",
releaseDate: "July 11, 1960"
},
{
title: "The Great Gatsby",
author: "F Scott Fitzgerald",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/great_gatsby.jpg",
releaseDate: "April 10, 1925"
},
{
title: "Les Miserables",
author: "Victor Hugo",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/les_miserables.jpg",
releaseDate: "Unknown 1862"
},
{
title: "Around the World in 80 Days",
author: "Jules Verne",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/around_the_world_in_80_days.jpg",
releaseDate: "January 30, 1873"
},
{
title: "Lean In",
author: "Sheryl Sandberg",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/lean_in.jpg",
releaseDate: "March 11, 2013"
},
{
title: "The Four Hour Workweek",
author: "Tim Ferriss",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/four_hour_work_week.jpg",
releaseDate: "April 1, 2007"
},
{
title: "Of Mice and Men",
author: "John Steinbeck",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/of_mice_and_men.jpg",
releaseDate: "Unknown 1937"
},
{
title: "Romeo and Juliet",
author: "William Shakespeare",
image: "https://s3-us-west-2.amazonaws.com/sandboxapi/romeo_and_juliet.jpg",
releaseDate: "Unknown 1597"
}
];
// remove all records that match {} -- which means remove ALL records
db.Book.remove({}, function(err, books){
if(err) {
console.log('Error occurred in remove', err);
} else {
console.log('removed all books');
// create new records based on the array books_list
db.Book.create(books_list, function(err, books){
if (err) { return console.log('err', err); }
console.log("created", books.length, "books");
process.exit();
});
}
});