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
Export as PDF
  1. Database
  2. Models/Classes

Serialization

PreviousInitialization/ConstructorNextThe &basic decorator

Last updated 4 years ago

You might also need a serialization method in the model for getting all values of the table in the format of ex. a dictionary. A serialization method can look like this:

It's good practice to call the serialization method s(), that way you can also utilize the built-in function.

Example

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)
    
    def _init(self, column1, column2):
        self.column1 = column1,
        self.column2 = column2

    def s(self):
        return {
            id: self.id,
            column1: self.column1,
            column2: self.column2
        }
serialize()