I'm creating a library that contains Bot class. I want it to be able to store messages logs and some other info in the sql database with the help of the pony orm. Idea is for the bot to accept the path to the database and create it or connect to it if it already exists.
Sadly, it seems that with pony I can only define classes after creation of the database object, needing to inherit from database.Entity class to bind my class to the database.
Obvious solution is to define all classes in the Bot class constructor after the creation of the database, but it seems quite ugly in terms of structure, because I plan those classes to be quite large, and wanted to store them in separate files.
Other hypothetical way is to do following (but I don't know whether that functionality is supported):
from pony import orm
class Message(orm.Entity):
text = orm.Required(unicode)
class Database(orm.Database):
def __init__(self, path):
# super(..).__init__(..)
# bind Message to self
class Bot(object):
def __init__(self, path):
self.database = Database(path)
Yet another possible hypothetical way would be if I could inherit from Database.Entity.
Any ideas? Maybe I can achieve this with another ORMs like SQLAlchemy?
You can try this pattern: