I’d like to be able to create MySQL Document Store Collections via simple SQL DDL statements rather than using the X-Protocol clients.
Is there any way to do so?
Edit: I’ll try and clarify the question.
Collections are tables using JSON datatypes and functions. That much is clear. I would like know how I can create a Collection without using the X-Protocol calls and make sure that the aforementioned collection is picked up as an actual Collection.
Judging from MySQL workbench, collection tables have a _id blob PK with an expression, a doc JSON column and a few other elements I do not recall at the moment (might be indexes, etc).
I have no means to tell via the Workbench whatever additional schema/metadata information is required for a table to be considered a Document Store Collection, or if the mere presence of an _id and doc columns are enough.
I hope this clears things up.
All "x-api" instructions are directly mapped to sql syntax. When you e.g. run
db.createCollection('my_collection')
, MySQL will literally just executeYou can run the corresponding sql statements yourself if you follow that format. The
doc
and_id
(with their type and the given expression) are required, the_json_schema
is optional, the check too (and only added since MySQL 8.0.17). Since MySQL 8, no additional columns are allowed, except generated columns that useJSON_EXTRACT
ondoc
and which are supposed to be used in an index, see below (although they don't actually have to be used in an index).Any table that looks like that -
doc
and_id
with their correct type/expression and no other columns except an optional_json_schema
and generatedJSON_EXTRACT(doc,
-columns - will be found withgetCollections()
.To add an index, the corresponding syntax for
would be
Obviously,
simply translates to
Similarly, all CRUD operations on documents have a corresponding sql DML syntax (that will actually be executed when you use them via x-api).