"""Step D CRUD benchmark against Postgres (Rust-native path, no GIL)."""
import sys
from justapi import JustAPIApp, Database
PORT = sys.argv[1] if len(sys.argv) > 1 else "8099"
PGURL = sys.argv[2] if len(sys.argv) > 2 else "postgres://avnadmin:<SECRET_PASSWORD>@dexmorgan-examhallorhell-5f8c.d.aivencloud.com:11100/defaultdb?sslmode=require"
INIT = (
"DROP TABLE IF EXISTS justapi_bench_items;"
"CREATE TABLE justapi_bench_items ("
"id BIGSERIAL PRIMARY KEY, name TEXT NOT NULL, qty INTEGER NOT NULL);"
)
app = JustAPIApp()
app.set_database(
Database(PGURL, max_connections=20, init_sql=INIT),
)
COLUMNS = ["name", "qty"]
app.post("/items", crud_table="justapi_bench_items", crud_columns=COLUMNS)
app.get("/items/{id}", crud_table="justapi_bench_items", crud_columns=COLUMNS)
app.put("/items/{id}", crud_table="justapi_bench_items", crud_columns=COLUMNS)
app.delete("/items/{id}", crud_table="justapi_bench_items", crud_columns=COLUMNS)
if __name__ == "__main__":
app.run(f"127.0.0.1:{PORT}")