From 830e7c5d27d161b91402414e6ecd49f1ed818bfb Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 27 Mar 2026 08:48:05 +0100 Subject: Initial commit --- lib/query/tests/create.t | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 lib/query/tests/create.t (limited to 'lib/query/tests/create.t') diff --git a/lib/query/tests/create.t b/lib/query/tests/create.t new file mode 100644 index 0000000..565235a --- /dev/null +++ b/lib/query/tests/create.t @@ -0,0 +1,150 @@ +Test the schema generated in the database. The tests create the database +in memory according the configuration given, then display the schema for a +specfic table. (The schema is extracted from the table, and requires the table +to be succesfully created). + +Test a single content with no field: + + $ tests -schema "entity" < { + > "content": [ + > { + > "id": "entity", + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY ) + +Text fields or numeric fields are created as columns directly in the table: + + $ tests -schema "entity" < { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "name", + > "label": {}, + > "type": "text", + > "required": true + > }, + > { + > "name": "year", + > "label": {}, + > "type": "integer" + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY + , "year" INTEGER + , "name" VARCHAR ) + +A subcontent is linked to the parent: + + $ tests -schema "details" < { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details" + > } + > ] + > } + > ] + > } + > EOF + CREATE TABLE "details" + ( "parent" INTEGER NOT NULL + , "id" INTEGER PRIMARY KEY + , FOREIGN KEY("parent") REFERENCES entity("id") ) + +A reference field is declared as a foreign key to the linked element + + $ tests -schema "entity" < { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "name", + > "label": {}, + > "type": "text", + > "required": true + > }, + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > "multivaluated": false + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY + , "user_type" INTEGER + , "name" VARCHAR + , FOREIGN KEY("user_type") REFERENCES user_type_list("id") ) + +When the field is multivaluated, there is no column for this property in the +table but a dedicated table is created: + + $ tests -schema "entity" "entity.user_type" < { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > "multivaluated": true + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + CREATE TABLE "entity" + ( "id" INTEGER PRIMARY KEY ) + CREATE TABLE "entity.user_type" + ( "id" INTEGER PRIMARY KEY + , "parent" INTEGER NOT NULL + , "target" INTEGER NOT NULL + , FOREIGN KEY("parent") REFERENCES entity("id") + , FOREIGN KEY("target") REFERENCES user_type_list("id") ) -- cgit v1.2.3