Toot

Written by Feoh on 2025-01-20 at 00:16

Just here to say that writing SQL backed REST APIs with @tiangolo's @FastAPI and SQLModel is easier than falling off a log!

sqlite_url='sqlite:///' + sqlite_file_name

engine = create_engine(sqlite_url)

engine = create_engine(sqlite_url, echo=True)

SQLModel.metadata.create_all(engine)

app = FastAPI()

@app.get("/player/create/{player_name}")

def create_player(player_name: str):

with Session(engine) as session:

    player = Player(name=player_name)

    session.add(player)

    session.commit()

@app.get("/player/delete/{player_id}")

def delete_player(player_id: int):

with Session(engine) as session:

    player = session.get(Player, player_id)

    session.delete(player)

    session.commit()

@app.get("/player/get/{player_id}")

def get_player(player_id: int):

with Session(engine) as session:

    player = session.get(Player, player_id)

    return player

@app.get("/thing/create/{thing_name}")

def create_thing(thing_name: str):

with Session(engine) as session:

    thing = Thing(name=thing_name)

    session.add(thing)

    session.commit()

@app.get("/thing/get/{thing_id}")

def get_thing(thing_id: int):

with Session(engine) as session:

    thing = session.get(Thing, thing_id)

    return thing

The people who say #python is so 5 minutes ago aren't paying attention. The community just keeps ratcheting up the level of awesome, and I am incredibly grateful for all the hard work everyone has put in!

=> More informations about this toot | View the thread | More toots from feoh@oldbytes.space

Mentions

=> View tiangolo@fosstodon.org profile | View FastAPI@fosstodon.org profile

Tags

=> View python tag

Proxy Information
Original URL
gemini://mastogem.picasoft.net/toot/113857800726683977
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
482.720035 milliseconds
Gemini-to-HTML Time
0.776639 milliseconds

This content has been proxied by September (ba2dc).