Columns

Columns are defined at the top of the model.

db_model MyModel:
    id = db.col(db.int, db.pk)
    column1 = db.col(db.str(100))
    column2 = db.col(db.float, db.unique, db.nullable)

    ...

Columns are described by:

  • a data type.

  • (optional) a maximum length of the data (see line 3 in the example).

  • (optional) additional attributes.

Column Data Types

  • int: Integer (whole number, ex. 35).

  • str: String (a sequence of characters).

  • float: Floating point number (ex. 3.5).

  • bool: Boolean value (True or False).

  • bytes: Bytes array.

  • datetime: Datetime type (Python datetime object).

  • list_id: An alias for int, can be used to improve readability when working with database lists.

Other Attributes

  • pk : Primary key.

  • unique: Unique.

  • nullable: Nullable.

  • basic_ignore: Ignore the column in the basic decorator code.

Example

db_model Product:
    id = db.col(db.int, db.pk)
    name = db.col(db.str(100), db.unique)
    description = db.col(db.str(200))
    price = db.col(db.float)
    qty = db.col(db.int)
    
    ...

Last updated