[Python] how to update dynamodb with pynamodb ORM?

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I'm creating a user table in dynamo db and want to utilize pynamodb ORM, sample class below.

    pynamodb class

    from pynamodb.models import Model
    from pynamodb.attributes import UnicodeAttribute

    class UserModel(Model):
    class Meta:
    table_name = "user"
    first_name = UnicodeAttribute(range_key=True)
    last_name = UnicodeAttribute(hash_key=True)
    email = UnicodeAttribute(null=True)



    I also have a pydantic class for data validation , see below. which validates the data, when client posts data to my REST API. Now i need to update my dynamo db table , to add another attribute , say age. I understand dynamodb doesn't really have a schema, per say. so we can add/update any attributes in the table, but when we use pynamodb ORM, do i just update the UserModel class above? add another attribute age to my UserModel class and also to my pydantic class. is there anything i need to update?

    from datetime import date
    from uuid import UUID, uuid4
    from enum import Enum
    from pydantic import BaseModel, EmailStr


    class User(BaseModel):
    first_name : str
    last_name : str
    email: str


    I want to update

    Continue reading...

Compartilhe esta Página