-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
31 lines (26 loc) · 1.08 KB
/
main.ts
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
// get the client
import mysql from "npm:mysql2/promise";
// create the connection to database
const connection = await mysql.createConnection({
host: "localhost",
user: "root",
password: "password",
});
await connection.query("CREATE DATABASE denos");
await connection.query("use denos");
await connection.query(
"CREATE TABLE `dinosaurs` ( `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) NOT NULL, `description` varchar(255) )"
);
await connection.query(
"INSERT INTO `dinosaurs` (id, name, description) VALUES (1, 'Aardonyx', 'An early stage in the evolution of sauropods.'), (2, 'Abelisaurus', 'Abels lizard has been reconstructed from a single skull.'), (3, 'Deno', 'The fastest dinosaur that ever lived.')"
);
const [select_all_results, select_all_fields] = await connection.query(
"SELECT * FROM `dinosaurs`"
);
console.log(select_all_results);
const [select_one_results, select_one_fields] = await connection.query(
"SELECT * FROM `dinosaurs` WHERE `name` = 'Deno'"
);
console.log(select_one_results);
// close the connection
await connection.end();