-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-db.js
50 lines (40 loc) · 2.05 KB
/
setup-db.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
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./db.sqlite3')
function setup() {
db.serialize(() => {
db.run('CREATE TABLE posts (title TEXT, body TEXT, date TEXT)')
const stmt = db.prepare('INSERT INTO posts VALUES (?, ?, ?)')
posts.forEach((post) => stmt.run(post.title, post.body, post.date))
stmt.finalize()
db.each('SELECT rowid AS id, * FROM posts', (err, row) => {
console.log(row)
})
})
}
const posts = [
{
title: 'Finished server-side blog project',
body: `Finished server-side blog project Finished server-side blog project Finished server-side blog project Finished server-side blog project
Finished server-side blog project Finished server-side blog project Finished server-side blog project`,
date: "2023-10-26T20:59:54.070Z",
},
{
title: 'Posts can now can be posted to DB',
body: `Posts can now can be posted to DB Posts can now can be posted to DB Posts can now can be posted to DB Posts can now can be posted to DB Posts can now can be posted to DB Posts can now can be posted to DB
Posts can now can be posted to DB Posts can now can be posted to DB Posts can now can be posted to DB Posts can now can be posted to DB Posts can now can be posted to DB `,
date: '2023-10-26T19:29:54.070Z',
},
{
title: 'Blog works fully server-side from DB',
body: `Blog works fully server-side from DB Blog works fully server-side from DB Blog works fully server-side from DB Blog works fully server-side from DB Blog works fully server-side from DB Blog works fully server-side from DB Blog works fully server-side from DB
Blog works fully server-side from DB Blog works fully server-side from DB `,
date: '2023-10-26T18:04:54.070Z',
},
{
title: 'Finished server-side blog project',
body: `Started server-side blog project Started server-side blog project Started server-side blog project Started server-side blog project
Started server-side blog project Started server-side blog project Started server-side blog project`,
date: '2023-10-26T15:39:54.070Z',
},
]
setup()