Relationship#

class sdgx.data_models.relationship.KeyTuple(parent, child)#
child#

Alias for field number 1

parent#

Alias for field number 0

pydantic model sdgx.data_models.relationship.Relationship[source]#

Relationship between tables

For parent table, we don’t need define primary key here. The primary key is pre-defined in parent table’s metadata.

Child table’s foreign key should be defined here.

Show JSON schema
{
   "title": "Relationship",
   "description": "Relationship between tables\n\nFor parent table, we don't need define primary key here.\nThe primary key is pre-defined in parent table's metadata.\n\nChild table's foreign key should be defined here.",
   "type": "object",
   "properties": {
      "version": {
         "default": "1.0",
         "title": "Version",
         "type": "string"
      },
      "parent_table": {
         "title": "Parent Table",
         "type": "string"
      },
      "child_table": {
         "title": "Child Table",
         "type": "string"
      },
      "foreign_keys": {
         "items": {
            "$ref": "#/$defs/KeyTuple"
         },
         "title": "Foreign Keys",
         "type": "array"
      }
   },
   "$defs": {
      "KeyTuple": {
         "maxItems": 2,
         "minItems": 2,
         "prefixItems": [
            {
               "title": "Parent"
            },
            {
               "title": "Child"
            }
         ],
         "type": "array"
      }
   },
   "required": [
      "parent_table",
      "child_table",
      "foreign_keys"
   ]
}

Fields:
field child_table: str [Required]#
field foreign_keys: List[KeyTuple] [Required]#

foreign keys.

If key is a tuple, the first element is parent column name and the second element is child column name

field parent_table: str [Required]#
field version: str = '1.0'#
classmethod build(parent_table: str, child_table: str, foreign_keys: Iterable[str | tuple[str, str] | KeyTuple], parent_metadata: Metadata | None = None, child_metadata: Metadata | None = None) Relationship[source]#

Build relationship from parent table, child table and foreign keys

Parameters:
  • parent_table (str) – parent table

  • parent_metadata – metadata of parent table

  • child_table (str) – child table

  • child_metadata – metadata of child table

  • foreign_keys (Iterable[str | tuple[str, str]]) – foreign keys. If key is a tuple, the first element is parent column name and the second element is child column name

classmethod load(path: str | Path) Relationship[source]#

Load relationship from json file.

save(path: str | Path)[source]#

Save relationship to json file.

classmethod upgrade(old_version: str, fields: dict[str, Any]) None[source]#