Select

Selecting row(s).

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='[email protected]')

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

MyModel.db.get_by(email='[email protected]').first()

Last updated