2025-01-28 10:18:57 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
2025-01-30 20:34:44 +01:00
|
|
|
from typing import Optional, Any
|
2025-01-28 10:18:57 +01:00
|
|
|
|
2025-01-30 20:34:44 +01:00
|
|
|
from .Column import Column
|
2025-01-28 10:18:57 +01:00
|
|
|
from .ColumnSet import ColumnSet
|
|
|
|
|
|
|
|
|
|
class SingleForeignKey:
|
|
|
|
|
|
2025-01-30 20:34:44 +01:00
|
|
|
def __init__(self, child_col: Column, parent_col: Column):
|
2025-01-28 10:18:57 +01:00
|
|
|
self.__child_col = child_col
|
|
|
|
|
self.__parent_col = parent_col
|
2025-01-30 20:34:44 +01:00
|
|
|
self.__iterable = (self.__child_col, self.__parent_col)
|
|
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
|
return 2
|
|
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
|
yield from self.__iterable
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return f'{self.__child_col.table.name}.{self.__child_col.name} -> {self.__parent_col.table.name}.{self.__parent_col.name}'
|
|
|
|
|
|
|
|
|
|
def __getitem__(self, index):
|
|
|
|
|
return self.__iterable[index]
|
2025-01-28 10:18:57 +01:00
|
|
|
|
|
|
|
|
@property
|
2025-01-30 20:34:44 +01:00
|
|
|
def child_column(self):
|
2025-01-28 10:18:57 +01:00
|
|
|
return self.__child_col
|
|
|
|
|
|
|
|
|
|
@property
|
2025-01-30 20:34:44 +01:00
|
|
|
def parent_column(self):
|
2025-01-28 10:18:57 +01:00
|
|
|
return self.__parent_col
|