Ask Documentation
WebsiteGitHubPyPI
  • Introduction
  • Getting Started
    • Install & Get Started
    • Hello, World!
  • Routes & Requests
    • Routes
    • Defining Routes
    • Request Data
    • HTTP Status Codes & Methods
    • CORS
  • Response
    • JSON Response
    • JSON Response With an HTTP Status Code
  • Classes
    • Class Instance Variable
    • Initialization/Constructor Method
  • Data Types
    • Dictionaries
  • Built-in Utilities
    • Quick_set()
    • Deep()
    • Serialize()
    • Require_keys()
    • Random Generators
    • Pattern Matching
    • Email
  • Database
    • Ask and Databases
    • Models/Classes
      • Columns
      • Initialization/Constructor
      • Serialization
      • The &basic decorator
    • CRUD
      • Add
      • Select
      • Update
      • Delete
    • Check if a Row Exists
    • Sorting
    • Database Lists
  • JWT Authentication
    • Introduction
    • Protecting Routes
    • How to Create a Basic Login System
    • Properties & Methods of _auth
    • Making Requests to Protected Routes
  • Decorators
    • What are Decorators?
    • Create and Use Custom Decorators
    • Built-in Decorators
  • Security
    • Hashing
    • Route Security
    • Environment Variables
  • Configuring the Transpiler
  • Askfile.toml
  • Modules & Libraries
    • Importing an Ask Module
    • Includes
    • Importing Python Modules
  • Development Tools
    • Editor Syntax Highlighting
    • Automatic API documentation
    • CLI Flags
    • Running in development mode
    • Versioning System
  • Contribute
    • Feature Requests
    • Bug Reports
    • Contribute Code
Powered by GitBook
On this page
  • Column Data Types
  • Other Attributes
  • Example
Export as PDF
  1. Database
  2. Models/Classes

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)
    
    ...
PreviousModels/ClassesNextInitialization/Constructor

Last updated 4 years ago