View Source Read

find-1

find/1

Returns entry with id matching what passed

iex(1)> Person.find(5)
%Person{
  __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
  id: 5,
  first_name: "Kristopher",
  last_name: "Keeling",
  age: 9
}

or find multiple entities with the provided identifiers like the following

iex(1)> Person.find([1, 2, 3])
[
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 1,
    first_name: "Bruen",
    last_name: "Sporer",
    age: 2
  },
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 2,
    first_name: "Herman",
    last_name: "Jerde",
    age: 2
  },
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 3,
    first_name: "Macey",
    last_name: "Treutel",
    age: 9
  }
]

all-0

all/0

Returns all database entries from a schema module

iex(1)> Person.all()
[
    %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 1,
    first_name: "German",
    last_name: "OConnell",
    age: 2
    },
    %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 2,
    first_name: "Fritsch",
    last_name: "Kassulke",
    age: 8
    },
    %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 3,
    first_name: "Russel",
    last_name: "Collins",
    age: 3
    }
]

take-1

take/1

or take a specific number of records

iex(1)> Person.take(2)
  [
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 1,
    first_name: "German",
    last_name: "OConnell",
    age: 2
  },
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 2,
    first_name: "Fritsch",
    last_name: "Kassulke",
    age: 8
  }
]

first-0

first/0

Returns the first table entry

iex(1)> Person.first()
%Person{
  __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
  id: 1,
  first_name: "Johnson",
  last_name: "Bradtke",
  age: 4
}

last-0

last/0

Returns the last table entry

iex(1)> Person.last()
%Person{
  __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
  id: 36,
  first_name: "Cedrick",
  last_name: "Donnelly",
  age: 2
}

except-1

except/1

Returns results except the records with the id provided

iex(1)> Person.all()
[
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 1,
    first_name: "Hudson",
    last_name: "Berge",
    age: 9
  },
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 2,
    first_name: "Hamill",
    last_name: "Wunsch",
    age: 2
  },
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 3,
    first_name: "Alden",
    last_name: "Kovacek",
    age: 0
  }
]
iex(2)> Person.except([1, 2])
[
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 3,
    first_name: "Alden",
    last_name: "Kovacek",
    age: 0
  }
]

Or provide only 1 record to exclude

iex(1)> Person.except(1)
[
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 2,
    first_name: "Hamill",
    last_name: "Wunsch",
    age: 2
  },
  %Person{
    __meta__: #Ecto.Schema.Metadata<:loaded, "people">,
    id: 3,
    first_name: "Alden",
    last_name: "Kovacek",
    age: 0
  }
]