Demo project
This tutorial show how to quickly create a playground for the database used on the MySQL Tutorial site.
- Start the mysql classicmodels database as a docker service:
docker run -d --name classicmodels -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password wsporto/classicmodels-mysql:8.0The image contains the sample database from the mysqltutorial.
Or if you want to create an empty mysql database, run:
docker run -d --name mysql8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=mydb mysql:8.0- Download the configured repository using degit:
npx degit github:wsporto/typesql-demo my-new-project- Go to project folder and install the dependencies:
cd ./my-new-projectnpm i- Run TypeSQL on watch mode:
npx typesql compile -w- Write the queries in the
./src/sqlsfolder:
SELECT productCode, productNameFROM productsORDER BY productNameLIMIT 5- Write the code using the generated functions:
const conn = await createConnection({ host: "localhost", database: "classicmodels", user: "root", password: "password",});
const products = await selectProducts(conn);- Execute the queries:
npm run devResult:
| (index) | productCode | productName |
|---|---|---|
| 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’ |