Fastapi sqlalchemy DBApi 直接使用sql語句

老榕树發表於2024-11-06
with engine.connect() as conn:
conn.execute(text("insert into teacher(user_id, name, subject) values(:a,:b,:c)"), [{"a": "88888888", "b": "叭叭叭巴巴爸爸", "c": "科目"}])
conn.commit()
result = conn.execute(text("select * from users"))
teachers = result.cursor.fetchall()
return {"teachers": teachers}

相關文章