Skip to content

Demo project

This tutorial show how to quickly create a playground for the database used on the MySQL Tutorial site.

  1. Start the mysql classicmodels database as a docker service:
Terminal window
docker run -d --name classicmodels -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password wsporto/classicmodels-mysql:8.0

The image contains the sample database from the mysqltutorial.

Or if you want to create an empty mysql database, run:

Terminal window
docker run -d --name mysql8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=mydb mysql:8.0
  1. Download the configured repository using degit:
Terminal window
npx degit github:wsporto/typesql-demo my-new-project
  1. Go to project folder and install the dependencies:
Terminal window
cd ./my-new-project
Terminal window
npm i
  1. Run TypeSQL on watch mode:
Terminal window
npx typesql compile -w
  1. Write the queries in the ./src/sqls folder:
./src/sqls/select-products.sql
SELECT
productCode,
productName
FROM products
ORDER BY productName
LIMIT 5
  1. Write the code using the generated functions:
src/main.ts
const conn = await createConnection({
host: "localhost",
database: "classicmodels",
user: "root",
password: "password",
});
const products = await selectProducts(conn);
  1. Execute the queries:
Terminal window
npm run dev

Result:

(index)productCodeproductName
0‘S24_2011’‘18th century schooner’
1‘S18_3136’‘18th Century Vintage Horse Carriage’
2‘S24_2841’‘1900s Vintage Bi-Plane’
3‘S24_4278’‘1900s Vintage Tri-Plane’
4‘S18_3140’‘1903 Ford Model A’