My goal is to access information about the wixData database structure (schema) of my site in code. For example, I would like to get the names of all of the data collections that currently exist and details about the fields within each collection (e.g. field key, data type, etc).
Having not yet figured out the “right” way to accomplish this, I have developed a temporary workaround, as described below. When I first started building the database, there were only a few collections, so the workaround was adequate, but now that there are a large number of collections and fields, it has become a lot more burdensome, and I’m really hoping someone can point me in the right direction. Any help will be greatly appreciated.
Thank you!
Tom
Description of the temporary workaround I have developed:
I have created a “Collection” collection and a “Field” collection (with a one-to-many relationship between the two collections… “Field” is a reference field (foreign key) in the “Collection” collection), and I’ve been using those collections to store information about my schema. It feels like I am reinventing the wheel, and I have encountered the following challenges:
-
The “Collection” and “Field” collections do not update dynamically, so every time I create a new collection or field in the database, I need to update those fields manually, which is time-consuming and feels redundant, since all of the schema / structure meta-data that I’m inputting is obviously already stored somewhere else.
-
There is no way to ensure that all data that is entered in these collections matches the actual schema, so errors can easily occur.