Home > Software engineering >  Can I create a Model from a TableConnection in PynamoDB?
Can I create a Model from a TableConnection in PynamoDB?

Time:05-26

I have existing DynamoDB tables created through an infrastructure-as-code implementation.

Within my application I would like to use the Model abstraction for this existing table.

I used TableConnection to connect to the existing table and run the lower level commands (get_item etc.).

Is there a way to create a Model from an existing TableConnection (without redefining the Model)?

Something like this:

table = TableConnection('ExistingTable')
ExistingTable = Model.create_model_from_existing(table)  # made up method
new_item  = ExistingTable('hash key', 'sort key')
new_item.save()

CodePudding user response:

Is there a way to create a Model from an existing TableConnection (without redefining the Model)?

No unfortunately, there’s no method to do that.

You will have to create the Model manually.

  • Related