neuralib.sqlp.annotation
- final class neuralib.sqlp.annotation.CURRENT_DATE[source]
annotated a date field which use current date as its default.
>>> class Example: ... a: Annotated[datetime.date, CURRENT_DATE]
- final class neuralib.sqlp.annotation.CURRENT_TIME[source]
annotated a time field which use current time as its default.
>>> class Example: ... a: Annotated[datetime.time, CURRENT_TIME]
- final class neuralib.sqlp.annotation.CURRENT_TIMESTAMP[source]
annotated a datetime field which use current datetime as its default.
>>> class Example: ... a: Annotated[datetime.datetime, CURRENT_TIMESTAMP]
- final class neuralib.sqlp.annotation.PRIMARY[source]
annotate a field as a primary key.
>>> class Example: ... a: Annotated[str, PRIMARY] # style 1
- final class neuralib.sqlp.annotation.UNIQUE[source]
annotated a field as a unique key.
>>> class Example: ... a: Annotated[str, UNIQUE] # style 1
- neuralib.sqlp.annotation.unique(conflict=None)[source]
A decorator to create an unique constraint.
- Parameters:
conflict (Literal['rollback', 'abort', 'fail', 'ignore', 'replace'] | None)
- 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
- neuralib.sqlp.annotation.check(field=None)[source]
A decorator to make a check constraint.
by a field
>>> class Example: ... a: str ... @check('a') ... def check_a(self): ... return self.a != ''
by over all
>>> class Example: ... a: str ... @check() ... def check_a(self): ... return self.a != ''
- Parameters:
field (str | None) – field name.