fredrikaverpil / postgres-playground

A personal PostgreSQL playground

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

postgres-playground

test

This is a personal testing playground of raw SQL queries and ORM queries for PostgreSQL written in Python, leveraging the Pytest framework. This allows for quick iteration and debugging when trying new stuff out.

Related:

Quickstart

Run

Run everything within containers:

docker compose build
docker compose up postgres --detach
docker compose run --rm pytest
docker compose down --volumes --remove-orphans

Run db in container and pytest locally:

poetry install
docker compose up postgres --detach
poetry run pytest
docker compose down --volumes --remove-orphans

Debug

Inspect database

To inspect the database while writing/running tests, set a breakpoint before the test completes and the db is reset. See either of the fixtures in tests/fixtures/orm/.

Then connect to localhost on port 5400.

SQL formatting

It's nice to have some sort of formatter/linter. For now, I'm using SQLTools in vscode when saving .sql files and occasionally run SQLFluff.

pipx install sqlfluff
sqlfluff lint --dialect postgres tests/**/*.sql
sqlfluff fix --dialect postgres tests/**/*.sql

About

A personal PostgreSQL playground

License:MIT License


Languages

Language:Python 95.8%Language:Dockerfile 4.2%