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
  • db.sort()
  • Usage
  • Example
Export as PDF
  1. Database

Sorting

How to sort selection query results.

db.sort()

Used for sorting database query results. You can either sort the results in a decending or an ascending order.

Usage

[select query object].db.sort(db.[desc/asc]([column]))

Parameters:

  • Either db.desc or db.asc.

  • Passed into the sorting order function.

  • Database model class column property (see the example).

Example

&basic
db_model MyModel:
    id = db.col(db.int, db.pk)
    number = db.col(db.int)
    column = db.col(...)
...

# Selects all rows in MyModel where the column "coumn" is set to "text".
# Sorts the rows in descending order by the column "number".
results = MyModel.db.get_by(column='text').db.sort(db.desc(MyModel.number))

...
PreviousCheck if a Row ExistsNextDatabase Lists

Last updated 4 years ago