How can the schema of WixData collections be retrieved via code?

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:

  1. 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.

  2. There is no way to ensure that all data that is entered in these collections matches the actual schema, so errors can easily occur.

No longer possible. There used to be an undocumented feature in wix-data that did just that, but it has been taken out several months ago.

Thank you for your quick reply. That is really too bad that the feature has been removed. I truly hope it gets reinstated, as it seems crazy that a database developer has no way to access their own schema information via code.

You could create a dumb record in the collection with every field populated and query it to retrieve the schema.