Skip to content
Star
478
Star
478

PostgreSQL

This guide shows you how to work with PostgreSQL locally using Docker Compose, SQLAlchemy, and Python. This lab demonstrates how to set up a containerized database with automatic schema initialization.

  1. Setup Environment:

    Open VS Code in the project folder and execute this command in the Command Palette:

    Terminal window
    > Dev Containers: Reopen in Container
  2. Run the Example:

    Terminal window
    python main.py
  1. Python Script (main.py):
    • Open the Run and Debug tab in VS Code.
    • Select the Python: Main configuration and start debugging.
  • All tests: Run the automated script: scripts/run_tests.sh
  • Individually: Use the VS Code Testing tab to run or debug specific test cases.

Run the following command to query the database directly (credentials from .env):

Terminal window
docker exec -it postgres_local psql -U admin -d testdb -c "SELECT * FROM users;"
Terminal window
docker compose down -v