-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cjs
57 lines (55 loc) · 1.81 KB
/
index.cjs
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 mysql = require('mysql2');
// Create a connection
const connection = mysql.createConnection({
host: 'localhost',
port: 33306,
user: 'otel',
password: 'secret',
database: 'test_db'
});
// Connect to the database
connection.connect((err) => {
if (err) {
console.error('Error connecting to the database:', err.stack);
return;
}
const dropTableQuery = `DROP TABLE IF EXISTS test_table2`;
connection.execute(dropTableQuery, (err, results) => {
if (err) {
console.error('Error executing query:', err.stack);
return;
}
const createTableQuery = `
CREATE TABLE test_table2 (
id INT AUTO_INCREMENT PRIMARY KEY,
value VARCHAR(255)
)
`;
connection.execute(createTableQuery, (err, results) => {
if (err) {
console.error('Error executing query:', err.stack);
return;
}
const insertQuery = 'INSERT INTO test_table2 (value) VALUES (?)';
connection.execute(insertQuery, ['Sample Value'], (err, results) => {
if (err) {
console.error('Error executing query:', err.stack);
return;
}
connection.query('SELECT * FROM test_table2', (err, results) => {
if(err) {
console.error('Error querying', err.stack)
return;
}
})
// Close the connection
connection.end((err) => {
if (err) {
console.error('Error closing the connection:', err.stack);
return;
}
});
});
});
});
});