forked from tbisho/snack-overflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbTest.js
80 lines (64 loc) · 1.77 KB
/
dbTest.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
72
73
74
75
76
77
78
79
80
const db = require('./models')
const methodOverride = require('method-override')
<<<<<<< HEAD
//test out db comment create
//create a comment and associate it with logged in user
db.comment.findOrCreate({
where: {
text: "this is the GOAT snack",
userId: 1,
snackId: 2
}
}).then(function([newComment]){
console.log(newComment.text)
})
// router.use(methodOverride('_method'))
// create a user for us to use
// db.user.create({
// name: "Susan Doolittle",
// email: "[email protected]",
// password: "erjwklejr"
// }).then( function(createdUser) {
// console.log(createdUser.dataValues)
// console.log('Successfully created ' + createdUser.dataValues.firstName)
// })
// db.user.findOrCreate({
// // constraint
// where: {
// id: 10
// }
// }).then(function([returnedUser, created]) {
// // Second step: findOrCreate a snack to associate with Susan
// const snack = req.params.id
// console.log(snack)
// db.snack.destroy({
// }).then(function() {
// // Last Step: associating the user to the snack - addSnack()
// // addSnack() is a method generated by Sequelize that uses the name of the model
// returnedUser.addSnack(returnedSnack).then( function(relationInfo) {
// console.log(relationInfo)
// console.log('-----------------------------')
// console.log(`${returnedSnack.name} added to ${returnedUser.name}`)
// })
// })
// })
// db.user.findOrCreate({
// where: {
// name: "Martin",
// email: "[email protected]"
// }
// }).then(([returnedUser, created]) => {
// db.snack.findAll({
// where: {name}
// })
// })
=======
>>>>>>> submain
db.comment.create({
userId: 1,
content: "This is the best snack"
}).then(function(comment){
console.log(comment.get())
}).catch((error)=>{
console.log(error)
})