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
  • Usage
  • Parameters
  • Example
Export as PDF
  1. Built-in Utilities

Serialize()

Easily serialize a list of database query objects.

Automatic serialization of database queries. Returns a list.

Usage

serialize(...)

Parameters

  • A list.

    • Of database query objects.

To be able to use serialize() your database models need to have their own serialization method called: s() (like in the examples in this documentation), or use the &basic decorator.

Example

db_model User:
    id = _db.col(_db.int, _db.pk)
    username = _db.col(_db.str(100))
    password = _db.col(_db.str(256))
    fname = _db.col(_db.str(100))
    sname = _db.col(_db.str(100))

    def init(self, username, password, fname, sname):
    self.username = username
    self.password = hash.hash(password)
    self.fname = fname
    self.sname = sname

    def s(self):
        return {
            username: self.username,
            name: self.fname + ' ' + self.sname
        }

@get('/users'):
    users = User.db.all()
    respond(serialize(users))
PreviousDeep()NextRequire_keys()

Last updated 4 years ago