Skip to content

fields.model_fields

is_field_nullable

1
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: flag explicit setting a column as nullable :type nullable: Optional[bool]
  • default: value or function to be called as default in python :type default: Any
  • server_default: function to be called as default by sql server :type server_default: Any
  • pydantic_only: flag if fields should not be included in the sql table :type pydantic_only: Optional[bool]

Returns:

result of the check :rtype: bool

is_auto_primary_key

1
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: flag if field is a pk field :type primary_key: bool
  • autoincrement: flag if field should be autoincrement :type autoincrement: bool

Returns:

result of the check :rtype: bool

convert_choices_if_needed

1
convert_choices_if_needed(field_type: "Type", choices: Set, nullable: bool, scale: int = None, represent_as_str: bool = False) -> Set

Converts dates to isoformat as fastapi can check this condition in routes and the fields are not yet parsed. Converts enums to list of it's values. Converts uuids to strings. Converts decimal to float with given scale.

Arguments:

  • field_type: type o the field :type field_type: Type
  • choices: set of choices :type choices: Set
  • scale: scale for decimals :type scale: int
  • nullable: flag if field_nullable :type nullable: bool
  • represent_as_str: flag for bytes fields :type represent_as_str: bool
  • scale: scale for decimals :type scale: int

Returns:

value, choices list :rtype: Tuple[Any, Set]

ModelFieldFactory Objects

1
class ModelFieldFactory()

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

validate

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

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

Arguments:

  • kwargs: all params passed during construction :type kwargs: Any

String Objects

1
class String(ModelFieldFactory,  str)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

validate

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

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

Arguments:

  • kwargs: all params passed during construction :type kwargs: Any

Integer Objects

1
class Integer(ModelFieldFactory,  int)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

Text Objects

1
class Text(ModelFieldFactory,  str)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

Float Objects

1
class Float(ModelFieldFactory,  float)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

DateTime Objects

1
class DateTime(ModelFieldFactory,  datetime.datetime)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

Date Objects

1
class Date(ModelFieldFactory,  datetime.date)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

Time Objects

1
class Time(ModelFieldFactory,  datetime.time)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

JSON Objects

1
class JSON(ModelFieldFactory,  pydantic.Json)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

BigInteger Objects

1
class BigInteger(Integer,  int)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

SmallInteger Objects

1
class SmallInteger(Integer,  int)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

Decimal Objects

1
class Decimal(ModelFieldFactory,  decimal.Decimal)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column

validate

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

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

Arguments:

  • kwargs: all params passed during construction :type kwargs: Any

UUID Objects

1
class UUID(ModelFieldFactory,  uuid.UUID)

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

get_column_type

1
2
 | @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: key, value pairs of sqlalchemy options :type kwargs: Any

Returns:

initialized column with proper options :rtype: sqlalchemy Column