-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
57 lines (47 loc) · 1.25 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
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./ws.db');
db.serialize(function() {
//criar tabela
db.run(`
CREATE TABLE IF NOT EXISTS ideas(
id INTEGER PRIMARY KEY AUTOINCREMENT,
image TEXT,
title TEXT,
category TEXT,
description TEXT,
link TEXT
);
`)
//inserir dados na tabela
// const query = `
// INSERT INTO ideas(
// image,
// title,
// category,
// description,
// link
// ) VALUES (?,?,?,?,?)
// `
// const values = [
// "https://image.flaticon.com/icons/svg/2729/2729007.svg",
// "Curso de Programação",
// "Estudo",
// " Lorem ipsu Lorem ipsu Lorem ipsu Lorem ipsu Lorem ipsu Lorem ipsu",
// "https://rocketseat.com.br"
// ]
// db.run(query, values, function(err){
// if(err) return console.log(err)
// console.log(this)
// })
//deletar um dado da tabela
// db.run(`DELETE FROM ideas WHERE id = ?`, [1], function(err){
// if(err) return console.log(err)
// console.log("Deletado", this)
// })
//consultar dados na tabela
// db.all(`SELECT * FROM ideas`, function(err, rows){
// if (err) return console.log(err)
// console.log(rows)
// })
})
module.exports = db;