-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.js
58 lines (46 loc) · 1.24 KB
/
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
51
52
53
54
55
56
57
58
const sqlite3 = require("sqlite3").verbose()
const db = new sqlite3.Database('./ws.db')
db.serialize(function(){
//Criar Tabela
db.run(`CREATE TABLE IF NOT EXISTS ideias(
id INTEGER PRIMARY KEY AUTOINCREMENT,
image TEXT,
title TEXT,
category TEXT,
description TEXT,
link TEXT
);`
)
//Inserir dados
const query = `
INSERT INTO ideias(
image,
title,
category,
description,
link
) VALUES(?,?,?,?,?);
`
const values = [
"https://image.flaticon.com/icons/svg/3021/3021831.svg",
"Flores no vaso",
"Flores",
"Lorem ipsum dolor, sit amet, adhuc nulla definiebas mei ad, ei doming aperiam delicata est.",
"https://www.linkedin.com/in/nathan-a-1b9436124/"
]
db.run(query, values, function(err){
if (err) return console.log(err)
console.log(this)
})
//Deletar dados da tabela
// db.run(`DELETE FROM ideias WHERE id = ?`, [1], function(err){
//if (err) return console.log(err)
// console.log("DELETE", this)
//})
//Consultar dados na tabela
// db.all(`SELECT * FROM ideias`, function(err, rows){
// if (err) return console.log(err)
// console.log(rows)
// })
})
module.exports = db