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.FieldA bool field.
-
class
aiomyorm.field.SmallIntField(primary_key=False, default=0, null=False, comment='', unsigned=False)¶ Bases:
aiomyorm.field.FieldA smallint field.
-
class
aiomyorm.field.MediumIntField(primary_key=False, default=0, null=False, comment='', unsigned=False)¶ Bases:
aiomyorm.field.FieldA mediumint field.
-
class
aiomyorm.field.IntField(primary_key=False, default=0, null=False, comment='', unsigned=False)¶ Bases:
aiomyorm.field.FieldA int field.
-
class
aiomyorm.field.BigIntField(primary_key=False, default=0, null=False, comment='', unsigned=False)¶ Bases:
aiomyorm.field.FieldA bigint field.
String Field¶
-
class
aiomyorm.field.StringField(length: int = 255, primary_key=False, default='', null=False, comment='')¶ Bases:
aiomyorm.field.FieldA 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.FieldA fixed length string field.
Text Field¶
-
class
aiomyorm.field.TextField(primary_key=False, default='', null=False, comment='')¶ Bases:
aiomyorm.field.FieldA text field.
-
class
aiomyorm.field.MediumTextField(primary_key=False, default='', null=False, comment='')¶ Bases:
aiomyorm.field.FieldA medium text field.
-
class
aiomyorm.field.LongTextField(primary_key=False, default='', null=False, comment='')¶ Bases:
aiomyorm.field.FieldA 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.FieldA 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.FieldA 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.FieldA 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.FieldA 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.FieldA datetime field, default value is today.
-
class
aiomyorm.field.TimeField(primary_key=False, default=datetime.timedelta(seconds=53927), null=False, comment='')¶ Bases:
aiomyorm.field.FieldA 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.FieldA 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)