-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.js
More file actions
34 lines (31 loc) · 1 KB
/
queries.js
File metadata and controls
34 lines (31 loc) · 1 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
const Tweets = {
createTable: `
CREATE TABLE IF NOT EXISTS tweets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
content TEXT NOT NULL,
user_id INTEGER NOT NULL,
created_at DATETIME NOT NULL
);
`,
create: `INSERT INTO tweets (content, user_id, created_at) VALUES (?, ?, ?);`,
findAll: `SELECT * FROM tweets;`,
findByUserId: `SELECT * FROM tweets WHERE user_id = ?;`,
};
const Users = {
createTable: `
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL,
created_at DATETIME NOT NULL
);
`,
create: `INSERT INTO users (name, email, created_at) VALUES (?, ?, ?);`,
findAll: `SELECT * FROM users;`,
findById: `SELECT * FROM users WHERE id = ?;`,
findByTweetId: `SELECT * FROM users WHERE id = (SELECT user_id FROM tweets WHERE id = ?);`,
};
module.exports = {
Tweets,
Users,
};