Files
ormar/docs/api/fields/model-fields.md

12 KiB

fields.model_fields

is_field_nullable

is_field_nullable(nullable: Optional[bool], default: Any, server_default: Any, pydantic_only: Optional[bool]) -> bool

Checks if the given field should be nullable/ optional based on parameters given.

Arguments:

  • nullable (Optional[bool]): flag explicit setting a column as nullable
  • default (Any): value or function to be called as default in python
  • server_default (Any): function to be called as default by sql server
  • pydantic_only (Optional[bool]): flag if fields should not be included in the sql table

Returns:

(bool): result of the check

is_auto_primary_key

is_auto_primary_key(primary_key: bool, autoincrement: bool) -> bool

Checks if field is an autoincrement pk -> if yes it's optional.

Arguments:

  • primary_key (bool): flag if field is a pk field
  • autoincrement (bool): flag if field should be autoincrement

Returns:

(bool): result of the check

ModelFieldFactory Objects

class ModelFieldFactory()

Default field factory that construct Field classes and populated their values.

_bases

_type

__new__

 | __new__(cls, *args: Any, **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

validate

 | @classmethod
 | validate(cls, **kwargs: Any) -> None

Used to validate if all required parameters on a given field type are set.

Arguments:

  • kwargs (Any): all params passed during construction

String Objects

class String(ModelFieldFactory,  str)

String field factory that construct Field classes and populated their values.

_type

__new__

 | __new__(cls, *, allow_blank: bool = True, strip_whitespace: bool = False, min_length: int = None, max_length: int = None, curtail_length: int = None, regex: str = None, **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

validate

 | @classmethod
 | validate(cls, **kwargs: Any) -> None

Used to validate if all required parameters on a given field type are set.

Arguments:

  • kwargs (Any): all params passed during construction

Integer Objects

class Integer(ModelFieldFactory,  int)

Integer field factory that construct Field classes and populated their values.

_type

__new__

 | __new__(cls, *, minimum: int = None, maximum: int = None, multiple_of: int = None, **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

Text Objects

class Text(ModelFieldFactory,  str)

Text field factory that construct Field classes and populated their values.

_type

__new__

 | __new__(cls, *, allow_blank: bool = True, strip_whitespace: bool = False, **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

Float Objects

class Float(ModelFieldFactory,  float)

Float field factory that construct Field classes and populated their values.

_type

__new__

 | __new__(cls, *, minimum: float = None, maximum: float = None, multiple_of: int = None, **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

DateTime Objects

class DateTime(ModelFieldFactory,  datetime.datetime)

DateTime field factory that construct Field classes and populated their values.

_type

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

Date Objects

class Date(ModelFieldFactory,  datetime.date)

Date field factory that construct Field classes and populated their values.

_type

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

Time Objects

class Time(ModelFieldFactory,  datetime.time)

Time field factory that construct Field classes and populated their values.

_type

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

JSON Objects

class JSON(ModelFieldFactory,  pydantic.Json)

JSON field factory that construct Field classes and populated their values.

_type

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

BigInteger Objects

class BigInteger(Integer,  int)

BigInteger field factory that construct Field classes and populated their values.

_type

__new__

 | __new__(cls, *, minimum: int = None, maximum: int = None, multiple_of: int = None, **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

Decimal Objects

class Decimal(ModelFieldFactory,  decimal.Decimal)

Decimal field factory that construct Field classes and populated their values.

_type

__new__

 | __new__(cls, *, minimum: float = None, maximum: float = None, multiple_of: int = None, precision: int = None, scale: int = None, max_digits: int = None, decimal_places: int = None, **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options

validate

 | @classmethod
 | validate(cls, **kwargs: Any) -> None

Used to validate if all required parameters on a given field type are set.

Arguments:

  • kwargs (Any): all params passed during construction

UUID Objects

class UUID(ModelFieldFactory,  uuid.UUID)

UUID field factory that construct Field classes and populated their values.

_type

__new__

 | __new__(cls, *, uuid_format: str = "hex", **kwargs: Any) -> Type[BaseField]

get_column_type

 | @classmethod
 | get_column_type(cls, **kwargs: Any) -> Any

Return proper type of db column for given field type. Accepts required and optional parameters that each column type accepts.

Arguments:

  • kwargs (Any): key, value pairs of sqlalchemy options

Returns:

(sqlalchemy Column): initialized column with proper options