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
  • 1. Selecting All / all()
  • 2. Selecting One Row by Id/Primary Key / get()
  • 3. Selecting All That Match / get_by()
Export as PDF
  1. Database
  2. CRUD

Select

Selecting row(s).

PreviousAddNextUpdate

Last updated 4 years ago

There are three ways of selecting rows.

  1. Selecting all rows that match a filter.

1. Selecting All / all()

This will select all rows in the table the MyModel model uses.

MyModel.db.all()

2. Selecting One Row by Id/Primary Key / get()

This will select the row in the table that has the id/primary key 5.

MyModel.db.get(5)

The reason we say id/primary key is that usually, you call the column that holds the primary key id but you don't have to, you can call it whatever you want.

3. Selecting All That Match / get_by()

This will select all rows in the table with the same email address in the email column.

MyModel.db.get_by(email='me@example.com')

This will return an array. You can get the first match by calling .first() after the get_by() method.

MyModel.db.get_by(email='me@example.com').first()

db.get_by() returns a list of matches (even if there's only one). Use .first() to get the first match (or only match if there's only one).

All rows in a table.
Selecting one row in a table, by id/primary key.