-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.js
More file actions
33 lines (24 loc) · 775 Bytes
/
create.js
File metadata and controls
33 lines (24 loc) · 775 Bytes
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
// Import database
const sqlite3 = require('sqlite3').verbose();
// Connect to the database (creates new database .db file if it doesnt yet exist)
let db = new sqlite3.Database('./people.db', (err) => {
if (err) {
console.error(err.message);
}
console.log('Connected to the people database.');
});
///////////////////////
// Create a table
let sql = 'CREATE TABLE contacts (' +
'contact_id INTEGER PRIMARY KEY,' +
'name TEXT NOT NULL,' +
'email TEXT NOT NULL UNIQUE,' +
'age integer NOT NULL' +
');';
db.run(sql);
///////////////////////
// Insert a row into the table
let sql_insert = 'INSERT INTO contacts (contact_id,name,email,age) VALUES (1, "John Doe", "jon@somthing.com", 25);'
db.run(sql_insert);
// close the database connection
db.close();