Skip to content

Instantly share code, notes, and snippets.

@henrebotha
Last active March 8, 2022 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save henrebotha/c82eb95a83c447a0e785c7d78bbe0576 to your computer and use it in GitHub Desktop.
Save henrebotha/c82eb95a83c447a0e785c7d78bbe0576 to your computer and use it in GitHub Desktop.
How to set up a TypeORM playground

How to set up a TypeORM playground

This guide is intended for people who'd like to experiment with TypeORM in a hands-on fashion. I find this especially helpful when attempting to construct complex queries.

Prerequisites

You need Yarn and Docker installed.

Process

  1. Install TypeORM globally using yarn global add typeorm.
  2. Run typeorm init --name typeorm-playground --database mysql to create a directory called typeorm-playground containing your new project. You can replace mysql with the database of your choice.
  3. Move into the directory you created using cd typeorm-playground.
  4. Visit this docker-compose.yml file in the TypeORM GitHub repo. Copy it into your playground project directory. Remove every section under services except for the database you chose in step 2. (I've attached an example here of what the file should look like.)
  5. Run docker-compose up to start your database Docker image.
  6. Open a new terminal window to run the remaining commands.
  7. Run yarn install to install all your project dependencies.
  8. Run yarn start to run the playground project. It contains some example code with a User entity and some simple queries against it.
  9. Press CtrlC to exit the project.

That's it! Now you can edit the src/index.ts file to play around with different queries.

version: "3"
services:
mysql:
image: "mysql:5.7.24"
container_name: "typeorm-mysql"
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "admin"
MYSQL_USER: "test"
MYSQL_PASSWORD: "test"
MYSQL_DATABASE: "test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment