Skip to content
Advertisement

PonyORM Database Table Dynamic Definition

As far as I know from the research I’ve made, the typical way of defining a table using PonyORM in Python is like the following:

My Problem: this uses db.entity

I wish to define a table without using the specific Databse instance in an abstract general manner, and connect it to the instance when I need to.

is there a way to do so?

concept (not real runnable code presumably):

EDIT:

One idea I have is to create a wrapper class for the database I wish to use with a certain group of tables, and define the tables in the init, because the whole point of me wishing to define tables dynamically is to seperate the Database instance creation from the table classes’ definitions, namely:

but then I have issues in accessing the database tables…

Advertisement

Answer

First of all you’re working with Entities, not Tables. They’re not the same thing.

Your problem can be solved just defining the function like factory

And then later when you create your Database instance you just call

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement