I am new to FastAPI and am playing around to get to know the framework. I am trying to insert data into my database but I am missing something.
Here's my model:
from datetime import datetime
from pydantic import BaseModel
class Article(BaseModel):
id: int
title: str
slug: str
content: str
author: str
date: datetime
class InArticle(BaseModel):
title: str
slug: str
content: str
author: str
and here's the logic
@app.post("/articles", response_model=InArticle)
async def create_article(article: InArticle):
cursor = connexion.cursor()
article_obj = (InArticle(
title=article.title,
slug=article.slug,
content=article.content,
author=article.author
))
db_query = """INSERT INTO Article (title, slug, content, author)
VALUES (?, ?, ?, ?)"""
cursor.execute(db_query, article_obj)
connexion.close()
return article
I get this error:
cursor.execute(db_query, article_obj)
ValueError: parameters are of unsupported type
What am I missing ?