Endon.first

You're seeing just the function first, go back to Endon module for more information.
Link to this function

first(count \\ 1, opts \\ [])

View Source

Specs

first(integer(), keyword()) :: [Ecto.Schema.t()] | Ecto.Schema.t() | nil

Get the first count records.

If you ask for one thing (count of 1), you will get back the first record or nil if none are found. If you ask for more than one thing (count > 1), you'll get back a list of 0 or more records.

If no order is defined it will order by primary key ascending.

Options

  • :order_by - By default, orders by primary key descending
  • :conditions - Limit results to those matching these conditions. Value can be anything accepted by where/2 (including a Ecto.Query.t/0).

Examples

 # get the first 3 posts, will return a list
 posts = Post.first(3)

 # get the first post, will return one item (or nil if none found)
 post = Post.first()

 # get the first 3 posts by author id 1
 posts = Post.first(3, conditions: [author_id: 1])