Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I create a new ORM object with information passed via JSON? #246

Open
moonman239 opened this issue Oct 25, 2022 · 1 comment
Open

Comments

@moonman239
Copy link

I have an ORM class created with SQLAlchemy, example:

class Person(Base):
    name = Column(String,nullable=False)
    birthdate = Column(String,CheckConstraint("birthdate >= '1970-01-01'")
    ssn = Column(String,primary_key=True)

My Flask app will be in charge of retrieving and inserting ORM objects like so:

@app.route("/people/<ssn>/insert",methods=["PUT"])
def insert_person(ssn):
    # insert person into database

The information to be inserted will be provided within the request, via a JSON string, ex:
{"name":"Bobby Burger","ssn":"123-45-6789"}
I already have a schema defined that I won't mention here.

I want to create an ORM object filled with the information provided.
How do I do this?

@sponsfreixes
Copy link

I already have a schema defined that I won't mention here.

To be able to help you better, this piece of information would help identifying if that's being done correctly.

What you are looking for is using load on the schema to convert the json to an object: https://marshmallow.readthedocs.io/en/stable/quickstart.html#deserializing-objects-loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants