neuralib.sqlp.annotation.foreign
- neuralib.sqlp.annotation.foreign(*field, update='NO ACTION', delete='NO ACTION')[source]
A decorator to create a foreign constraint.
Common use:
With a foreign table
>>> class ForeignTable: ... a: Annotated[str, str] ... b: Annotated[str, str]
mapping one-by-one
>>> class Example: ... a: Annotated[str, str] ... b: Annotated[str, str] ... @foreign(ForeignTable.a, ForeignTable.b) ... def _foreign(self): ... return self.a, self.b
by default, with the primary keys for the referred foreign table.
>>> class Example: ... a: Annotated[str, str] ... b: Annotated[str, str] ... @foreign(ForeignTable) ... def _foreign(self): ... return self.a, self.b
Self refered.
>>> class Example: ... a: Annotated[str, str] ... b: Annotated[str, str] ... @foreign('a') ... def _foreign(self): ... return self.b
- Parameters:
field – a foreign table or foreign fields.
update (Literal['SET NULL', 'SET DEFAULT', 'CASCADE', 'RESTRICT', 'NO ACTION']) – update policy
delete (Literal['SET NULL', 'SET DEFAULT', 'CASCADE', 'RESTRICT', 'NO ACTION']) – delete policy