Replies: 1 comment
-
Currently, I am using a naive workaround, to ensure only one instance of the class. I added a primary key, that will contain the value class AdminConfig(Model):
one_id:int = Field(primary_field=True)
# blah blah Now to access the document, I am using the admin_cfg = await engine.find_one(AdminConfig,AdminConfig.one_id==1)
if not admin_cfg:
admin_cfg = await engine.save(AdminConfig(one_id=1))
admin_cfg: AdminConfig Is there a more mature or standard way of achieving what I am trying to do ? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For my application, I have some global configuration, which I want to persist in my database.
The model definition is something like this
Now, I want only one instance of the class to exist. Thus, there will be only one document in the AdminConfig collection, at a point in time.
I think using a capped collection is the way to go, so that only one document is allowed.
In the model definition, is there a way to define before hand, that the cap is one instance ?
Beta Was this translation helpful? Give feedback.
All reactions