Files
Portfolio/main.py
T
2025-05-31 17:04:40 +00:00

21 lines
557 B
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from fastapi import FastAPI
import mariadb
app = FastAPI()
@app.get("/api/portfolio")
def read_portfolio():
  try:
    conn = mariadb.connect(
      user="root",
      password="motdepasse",
      host="localhost",
      port=3306,
      database="portfolio"
    )
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM portfolio;")
    result = cursor.fetchall()
    conn.close()
    return {"data": result}
  except mariadb.Error as e:
    return {"error": str(e)}