-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample-setup.js
More file actions
53 lines (49 loc) · 1.24 KB
/
example-setup.js
File metadata and controls
53 lines (49 loc) · 1.24 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
const db = require("./models/index.js");
const { updateOrCreate } = require("./utils/models.js");
const bcrypt = require("bcryptjs");
async function initDb() {
console.log(
"Will rewrite the SQLite example database, adding some dummy data."
);
await db.sequelize.sync();
const userObject = {
full_name: "Test User",
username: "test",
email: "testemail@gmail.com",
password: bcrypt.hashSync("1234"),
is_email_verified: false,
};
const anotherUser = {
full_name: "Another Test",
username: "another",
email: "another@test.com",
password: bcrypt.hashSync("12345678"),
is_email_verified: false,
};
updateOrCreate(
db.sequelize.models.User,
{ email: userObject["email"] },
userObject
)
.then(function (result) {
result.item; // the model
result.created; // bool, if a new item was created.
})
.catch(function (err) {
console.log(err);
});
updateOrCreate(
db.sequelize.models.User,
{ email: anotherUser["email"] },
anotherUser
)
.then(function (result) {
result.item; // the model
result.created; // bool, if a new item was created.
})
.catch(function (err) {
console.log(err);
});
console.log("Done!");
}
initDb();