Difference between revisions of "Relation Table"

From truxwiki.com
Jump to navigation Jump to search
(Created page with "This table stores the relationships between things in Truxton. <syntaxhighlight lang="SQL"> CREATE TABLE "Relation" ( "A_ID" uuid NOT NULL, "B_ID" uuid NOT NULL,...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
This table stores the relationships between things in Truxton.
 
This table stores the relationships between things in Truxton.
 +
This is how the [https://en.wikipedia.org/wiki/Graph_(discrete_mathematics) graph] of Truxton objects is stored.
  
<syntaxhighlight lang="SQL">
+
=SQL=
CREATE TABLE "Relation" (
+
<source lang="SQL">
    "A_ID" uuid NOT NULL,
+
CREATE TABLE "Relation"
    "B_ID" uuid NOT NULL,
+
(
    "A_ObjectTypeID" smallint NOT NULL,
+
  "A_ID" uuid NOT NULL,
    "B_ObjectTypeID" smallint NOT NULL,
+
  "B_ID" uuid NOT NULL,
    "RelationTypeID" integer NOT NULL,
+
  "A_ObjectTypeID" smallint NOT NULL,
    "SourceID" uuid NOT NULL,
+
  "B_ObjectTypeID" smallint NOT NULL,
    "SourceObjectTypeID" smallint NOT NULL
+
  "RelationTypeID" integer NOT NULL,
 +
  "SourceID" uuid NOT NULL,
 +
  "SourceObjectTypeID" smallint NOT NULL
 
);
 
);
</syntaxhighlight>
+
</source>
 +
 
 +
=Columns=
 +
==<code>A_ID</code>==
 +
The globally unique identifier of the first item.
 +
 
 +
==<code>B_ID</code>==
 +
The globally unique identifier of the second item.
 +
 
 +
==<code>A_ObjectTypeID</code>==
 +
What type A is.
 +
This corresponds to the <code>ID</code> column of the <code>[ObjectType]</code> table.
 +
It should be one of [[Object_Types|these]] values.
 +
 
 +
==<code>B_ObjectTypeID</code>==
 +
What B is.
 +
This corresponds to the <code>ID</code> column of the <code>[ObjectType]</code> table.
 +
It should be one of [[Object_Types|these]] values.
 +
 
 +
==<code>RelationTypeID</code>==
 +
What relates these two items.
 +
This corresponds to the <code>ID</code> column of the <code>[RelationType]</code> table.
 +
It should be one of [[Relation_Types|these]] types.
 +
 
 +
==<code>SourceID</code>==
 +
What related these two items. This uuid points to the reason why we added this record to the table.
 +
 
 +
==<code>SourceObjectTypeID</code>==
 +
The type of <code>Source</code>.
 +
This corresponds to the <code>ID</code> column of the <code>[ObjectType]</code> table.
 +
It should be one of [[Object_Types|these]] values.

Latest revision as of 05:56, 27 January 2024

This table stores the relationships between things in Truxton. This is how the graph of Truxton objects is stored.

SQL

CREATE TABLE "Relation"
(
  "A_ID" uuid NOT NULL,
  "B_ID" uuid NOT NULL,
  "A_ObjectTypeID" smallint NOT NULL,
  "B_ObjectTypeID" smallint NOT NULL,
  "RelationTypeID" integer NOT NULL,
  "SourceID" uuid NOT NULL,
  "SourceObjectTypeID" smallint NOT NULL
);

Columns

A_ID

The globally unique identifier of the first item.

B_ID

The globally unique identifier of the second item.

A_ObjectTypeID

What type A is. This corresponds to the ID column of the [ObjectType] table. It should be one of these values.

B_ObjectTypeID

What B is. This corresponds to the ID column of the [ObjectType] table. It should be one of these values.

RelationTypeID

What relates these two items. This corresponds to the ID column of the [RelationType] table. It should be one of these types.

SourceID

What related these two items. This uuid points to the reason why we added this record to the table.

SourceObjectTypeID

The type of Source. This corresponds to the ID column of the [ObjectType] table. It should be one of these values.