field

Basic Field

This is the most basic Field class, and all the common properties of all Field are given here, but I do not recommend you to use this class. I provide a more customized class later.

class aiomyorm.field.Field(column_type, default, primary_key=False, null=False, comment=None, unsigned=None)

A field is a mapping of a column in mysql table.

column_type

Type of this column.

Type:str
primary_key

Whether is a primary key.

Type:bool
default

The default value of this column, it can be a real value or a function.

Type:any
belong_model

The model(table) this field(column) belongs to.

Type:str
comment

Comment of this field.

Type:str
null

Allow null value or not.

Type:bool
unsigned

Whether unsigned. Only useful in Integer.

Type:bool

Integer Field

class aiomyorm.field.BoolField(primary_key=False, default=0, null=False, comment='')

Bases: aiomyorm.field.Field

A bool field.

class aiomyorm.field.SmallIntField(primary_key=False, default=0, null=False, comment='', unsigned=False)

Bases: aiomyorm.field.Field

A smallint field.

class aiomyorm.field.MediumIntField(primary_key=False, default=0, null=False, comment='', unsigned=False)

Bases: aiomyorm.field.Field

A mediumint field.

class aiomyorm.field.IntField(primary_key=False, default=0, null=False, comment='', unsigned=False)

Bases: aiomyorm.field.Field

A int field.

class aiomyorm.field.BigIntField(primary_key=False, default=0, null=False, comment='', unsigned=False)

Bases: aiomyorm.field.Field

A bigint field.

String Field

class aiomyorm.field.StringField(length: int = 255, primary_key=False, default='', null=False, comment='')

Bases: aiomyorm.field.Field

A string field.

Parameters:length (int) – Maximum length of string in this field, default by 255.
class aiomyorm.field.FixedStringField(length: int = 255, primary_key=False, default='', null=False, comment='')

Bases: aiomyorm.field.Field

A fixed length string field.

Text Field

class aiomyorm.field.TextField(primary_key=False, default='', null=False, comment='')

Bases: aiomyorm.field.Field

A text field.

class aiomyorm.field.MediumTextField(primary_key=False, default='', null=False, comment='')

Bases: aiomyorm.field.Field

A medium text field.

class aiomyorm.field.LongTextField(primary_key=False, default='', null=False, comment='')

Bases: aiomyorm.field.Field

A long text field.

Decimal Field

class aiomyorm.field.FloatField(total_digits: int = 255, decimal_digits: int = 30, primary_key=False, default=0.0, null=False, comment='')

Bases: aiomyorm.field.Field

A float field.

Parameters:
  • total_digits (int) – total digit for this float, default by 255.
  • decimal_digits (int) – total decimal digit, default by 30.
class aiomyorm.field.DoubleField(total_digits: int = 255, decimal_digits: int = 30, primary_key=False, default=0.0, null=False, comment='')

Bases: aiomyorm.field.Field

A double field.

Parameters:
  • total_digits (int) – total digit for this float, default by 255.
  • decimal_digits (int) – total decimal digit, default by 30.
class aiomyorm.field.DecimalField(total_digits: int = 65, decimal_digits: int = 30, primary_key=False, default=0.0, null=False, comment='')

Bases: aiomyorm.field.Field

A decimal field which is more precise than float or double.

Parameters:
  • total_digits (int) – total digit for this float, default by 65.
  • decimal_digits (int) – total decimal digit, default by 30.

DateTime Field

class aiomyorm.field.DatetimeField(primary_key=False, default=datetime.datetime(2022, 6, 19, 14, 58, 47), null=False, comment='')

Bases: aiomyorm.field.Field

A datetime field, default value is now.

class aiomyorm.field.DateField(primary_key=False, default=datetime.date(2022, 6, 19), null=False, comment='')

Bases: aiomyorm.field.Field

A datetime field, default value is today.

class aiomyorm.field.TimeField(primary_key=False, default=datetime.timedelta(seconds=53927), null=False, comment='')

Bases: aiomyorm.field.Field

A time field, default value is now time.

class aiomyorm.field.TimestampField(primary_key=False, default=datetime.datetime(2022, 6, 19, 14, 58, 47), null=False, comment='')

Bases: aiomyorm.field.Field

A timestamp field, default value is now.

More Field

You can customize your field class based on the Field, such as:

class JsonField(Field):
    """A json field."""
    def __init__(self, primary_key=False, default="{}", null=False, comment=''):
        super().__init__(column_type='json', primary_key=primary_key, default=default, null=null,
                         comment=comment)