-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
52 lines (46 loc) · 1.63 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
const sqlite3 = require('sqlite3').verbose()
const db = new sqlite3.Database('./ws.db') // (./) = referencia a pasta raiz do sistema
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 dado na tabela
// const query =`
// INSERT INTO ideias(
// image,
// title,
// category,
// description,
// link
// ) VALUES (?,?,?,?,?);`
// const values = [
// "/img/jogos.png" ,
// "Jogos" ,
// "Diversão",
// "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea sit accusamus suscipit corrupti illum, numquam tenetur quod iste quo laborum cupiditate sapiente soluta aperiam fuga iusto animi esse nam adipisci.",
// "https://www.linkedin.com/in/wendell-priebe-0113031a1/"
// ]
// db.run(query, values, function(err){
// if (err) return console.log(err)
// console.log(this)
// })
// consultar dados na tabela
db.all(`SELECT * FROM ideias`, function(err, rows){
if (err) return console.log(err)
console.log(rows)
})
// deletar um dado da tabela
// db.run(`DELETE FROM ideias WHERE id = ?`, [1], function(err){ //[1] = id do dado a deletar
// if (err) return console.log(err)
// console.log("DELETEI",this)
// })
})
module.exports = db //exporta o banco de dados