-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.js
More file actions
38 lines (31 loc) · 862 Bytes
/
sql.js
File metadata and controls
38 lines (31 loc) · 862 Bytes
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
// Generating query strings
function s_quote(str){
return "'" + str + "'";
}
// Fetch
function get_users(id){
return `SELECT * FROM DATA.USERS WHERE id=${s_quote(id)}`;
}
function get_posts(user_id){
return `SELECT * FROM DATA.POSTS WHERE user_id=${s_quote(user_id)}`;
}
// Add
function register(id, name, password, email){
return `INSERT INTO DATA.USERS (id, name, password, email) VALUES (${s_quote(id)}, ${s_quote(name)}, ${s_quote(password)}, ${s_quote(email)})`;
}
function add_post(user_id, mood, text){
return `INSERT INTO DATA.POSTS (user_id, mood, text) VALUES (${s_quote(user_id)}, ${s_quote(mood)}, ${s_quote(text)})`;
}
// Edit
// 暂且不写
// Del
function del_post(post_id){
return `DELETE FROM DATA.POSTS WHERE post_id=${s_quote(post_id)}`;
}
module.exports = {
get_users,
get_posts,
register,
add_post,
del_post
};