Postgres
Each run builds the database from schema.sql, fills users with everyone the requests sign in as, then sends the requests in request.http. create_post() and follow() add rows to posts and follows with the statements in schema.sql's comment.
Tables
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY | An id Postgres numbers for you: 1, 2, 3… |
col TEXT NOT NULL | Every row must have a value |
col TEXT UNIQUE | No two rows share a value |
col BIGINT REFERENCES users (id) | Must match a user's id. Postgres refuses a row that doesn't |
PRIMARY KEY (a, b) | No two rows share the pair, for a table with one row per pair |
col TIMESTAMPTZ NOT NULL DEFAULT now() | When the row was added |
CREATE INDEX name ON t (a, b DESC) | Finds the rows for one a fast, already sorted by b |
Queries
INSERT ... ON CONFLICT DO NOTHING | Skips a row that would break a primary key or unique constraint, as follow() does |
SELECT ... FROM a JOIN b ON b.x = a.y | Pairs each row of a with each row of b that matches it |
ORDER BY col DESC LIMIT 20 | The 20 rows with the highest col, highest first |
Python
await find_user(username) | The user's row, like {"id": 1, "username": "ada"}, or None |
await postgres.query(sql, params) | Runs one statement and returns its rows, as a list of dicts. %(name)s in sql is params["name"] |
Response(status=200, json={"posts": rows}) | A response with a JSON body. Rows from postgres.query can go in as they are |
Postgres returns timestamps as ISO 8601 text, like "2026-10-31T09:00:00.000Z".
Python · 30 linesStarter code · Ctrl/⌘ + Enter to run
SystemBroke
No runs yet.
Run the simulation to send this kata's traffic to your code. Hidden checks grade what it does.