-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.js
53 lines (45 loc) · 1.03 KB
/
query.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
const User = require("./models").user;
const getAdminUsers = async () => {
try {
const users = await User.findAll({
where: { admin: true },
});
console.log("do I get users?", users);
} catch (e) {
console.log(e.message);
}
};
const getUserById = async (id) => {
try {
const user = await User.findByPk(id); // primary key => {} || undefined
console.log(user);
} catch (e) {
console.log(e.message);
}
};
const createUser = async (name, email, password) => {
try {
const newUser = await User.create({
name: name,
email: email,
password: password,
});
console.log(newUser);
} catch (e) {
console.log(e.message);
}
};
const deleteUser = async (id) => {
try {
const theUser = await User.findByPk(id);
console.log("i found the user!", theUser);
await theUser.destroy();
console.log("user deleted");
} catch (e) {
console.log(e.message);
}
};
// deleteUser(2);
// createUser("Alex", "[email protected]", "alex123");
getAdminUsers();
// getUserById(2);