Current section
Files
Jump to
Current section
Files
doc/dist/search_items-5A5DEDED.js
searchNodes=[{"type":"module","title":"Ecto.Entity","doc":"Entity The missing Elixir Phoenix package to achieve Ecto > 80% common operations with < 20% effort. Introduction Inspired by Laravel-Php Eloquent package, Entity includes injectable functions that makes it enjoyable to interact with your database. When using Entity, each database table has a corresponding Schema(Model) that is used to interact with that table. In addition to retrieving records from the database table, Entity allows you to insert, update, and delete records from the table as well. The goal of this package is to make it deadly simple to interact with Ecto without having to necessary write custom CRUD operations. Getting Started This guide is an introduction to Entity, the missing Phoenix Ecto package to achieve +80% of common operations less than 20% of effort it would normally take. Entity provides a standardized API and a set of abstractions for interacting with database tables, so that your phoenix Elixir developers can focus on what's specific to your project. In this guide, we're going to learn some basics about Entity, such as creating, reading, updating and destroying records from a database. If you want to see the code from this guide, you can view it at kamaroly/ecto_entity on GitHub . This guide will require you to have setup Entity beforehand. Install Entity in your Phoenix / Elixir App To add Entity to your application, The first step is to add Entity to your mix.exs file, which we'll do by changing the deps definition in that file to this: defp deps do [ { :ecto_entity , "~> 0.1.0" } ] end Then, to install it, you will run this command: mix deps . get To start off with, we'll need to include Entity in our existing Phoenix Schema like the following: defmodule MyApp.Person do import Ecto.Changeset use Ecto.Schema use Entity schema "people" do field :first_name , :string field :last_name , :string field :age , :integer end def changeset ( entity , attrs ) do entity |> cast ( attrs , [ :first_name , :last_name ] ) |> validate_required ( [ :first_name , :last_name ] ) end end The create/1 and insert/1 function You can use create or insert stores a new data entry. Schema module must have changeset method implementedUse the create method, which accepts an schema of attributes, creates, and inserts it into the database. The newly created schema will be returned by the create function. iex> Person . create ( %{ first_name : "Hand" , last_name : "Turner" , age : 3 } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 125 , first_name : "Hand" , last_name : "Turner" , age : 3 } } Reading methods The find/1 returns entry with id matching what passed iex> Person . find ( 5 ) % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 5 , first_name : "Kristopher" , last_name : "Keeling" , age : 9 } The all/0 function to return all table entries Retrieves all database entries from a schema module iex> 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 } ] The take/1 function to return x number of records iex> 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 } ] The first/0 function to return the first table entry The last/0 function to return the last table entry The update/2 function Updates a table record by ID iex> Person . update ( 1 , %{ first_name : "Kamaro" } ) iex> { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Kamaro" , last_name : "Yundt" , age : 7 } } Updates entity by its schema iex(1)> person = Person . find ( 1 ) % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Weber" , last_name : "Ok 2" , age : 7 } iex(2)> Person . update ( person , %{ first_name : "Kamaro" } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Kamaro" , last_name : "Ok 2" , age : 7 } } The delete/1 and destroy/ functions delete iex(2)> Person . delete ( 7 ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :deleted , "people" > , id : 7 , first_name : "Glover" , last_name : "Schimmel" , age : 2 } } destroy iex(3)> Person . destroy ( 2 ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :deleted , "people" > , id : 2 , first_name : "Ruecker" , last_name : "Lemke" , age : 0 } }","ref":"Ecto.Entity.html"},{"type":"module","title":"Ecto.Entity.Association","doc":"","ref":"Ecto.Entity.Association.html"},{"type":"module","title":"Ecto.Entity.Changes","doc":"","ref":"Ecto.Entity.Changes.html"},{"type":"module","title":"Ecto.Entity.Conditions","doc":"","ref":"Ecto.Entity.Conditions.html"},{"type":"module","title":"Ecto.Entity.Create","doc":"","ref":"Ecto.Entity.Create.html"},{"type":"module","title":"Ecto.Entity.DB","doc":"","ref":"Ecto.Entity.DB.html"},{"type":"module","title":"Ecto.Entity.Delete","doc":"","ref":"Ecto.Entity.Delete.html"},{"type":"module","title":"Ecto.Entity.Helpers","doc":"","ref":"Ecto.Entity.Helpers.html"},{"type":"macro","title":"Ecto.Entity.Helpers.__using__/1","doc":"Get the repo to use","ref":"Ecto.Entity.Helpers.html#__using__/1"},{"type":"module","title":"Ecto.Entity.Read","doc":"","ref":"Ecto.Entity.Read.html"},{"type":"module","title":"Ecto.Entity.Repo","doc":"","ref":"Ecto.Entity.Repo.html"},{"type":"function","title":"Ecto.Entity.Repo.aggregate/3","doc":"Callback implementation for Ecto.Repo.aggregate/3 .","ref":"Ecto.Entity.Repo.html#aggregate/3"},{"type":"function","title":"Ecto.Entity.Repo.aggregate/4","doc":"Callback implementation for Ecto.Repo.aggregate/4 .","ref":"Ecto.Entity.Repo.html#aggregate/4"},{"type":"function","title":"Ecto.Entity.Repo.all/2","doc":"Callback implementation for Ecto.Repo.all/2 .","ref":"Ecto.Entity.Repo.html#all/2"},{"type":"function","title":"Ecto.Entity.Repo.checked_out?/0","doc":"Callback implementation for Ecto.Repo.checked_out?/0 .","ref":"Ecto.Entity.Repo.html#checked_out?/0"},{"type":"function","title":"Ecto.Entity.Repo.checkout/2","doc":"Callback implementation for Ecto.Repo.checkout/2 .","ref":"Ecto.Entity.Repo.html#checkout/2"},{"type":"function","title":"Ecto.Entity.Repo.child_spec/1","doc":"","ref":"Ecto.Entity.Repo.html#child_spec/1"},{"type":"function","title":"Ecto.Entity.Repo.config/0","doc":"Callback implementation for Ecto.Repo.config/0 .","ref":"Ecto.Entity.Repo.html#config/0"},{"type":"function","title":"Ecto.Entity.Repo.default_options/1","doc":"Callback implementation for Ecto.Repo.default_options/1 .","ref":"Ecto.Entity.Repo.html#default_options/1"},{"type":"function","title":"Ecto.Entity.Repo.delete/2","doc":"Callback implementation for Ecto.Repo.delete/2 .","ref":"Ecto.Entity.Repo.html#delete/2"},{"type":"function","title":"Ecto.Entity.Repo.delete!/2","doc":"Callback implementation for Ecto.Repo.delete!/2 .","ref":"Ecto.Entity.Repo.html#delete!/2"},{"type":"function","title":"Ecto.Entity.Repo.delete_all/2","doc":"Callback implementation for Ecto.Repo.delete_all/2 .","ref":"Ecto.Entity.Repo.html#delete_all/2"},{"type":"function","title":"Ecto.Entity.Repo.disconnect_all/2","doc":"A convenience function for SQL-based repositories that forces all connections in the pool to disconnect within the given interval. See Ecto.Adapters.SQL.disconnect_all/3 for more information.","ref":"Ecto.Entity.Repo.html#disconnect_all/2"},{"type":"function","title":"Ecto.Entity.Repo.exists?/2","doc":"Callback implementation for Ecto.Repo.exists?/2 .","ref":"Ecto.Entity.Repo.html#exists?/2"},{"type":"function","title":"Ecto.Entity.Repo.explain/3","doc":"A convenience function for SQL-based repositories that executes an EXPLAIN statement or similar depending on the adapter to obtain statistics for the given query. See Ecto.Adapters.SQL.explain/4 for more information.","ref":"Ecto.Entity.Repo.html#explain/3"},{"type":"function","title":"Ecto.Entity.Repo.get/3","doc":"Callback implementation for Ecto.Repo.get/3 .","ref":"Ecto.Entity.Repo.html#get/3"},{"type":"function","title":"Ecto.Entity.Repo.get!/3","doc":"Callback implementation for Ecto.Repo.get!/3 .","ref":"Ecto.Entity.Repo.html#get!/3"},{"type":"function","title":"Ecto.Entity.Repo.get_by/3","doc":"Callback implementation for Ecto.Repo.get_by/3 .","ref":"Ecto.Entity.Repo.html#get_by/3"},{"type":"function","title":"Ecto.Entity.Repo.get_by!/3","doc":"Callback implementation for Ecto.Repo.get_by!/3 .","ref":"Ecto.Entity.Repo.html#get_by!/3"},{"type":"function","title":"Ecto.Entity.Repo.get_dynamic_repo/0","doc":"Callback implementation for Ecto.Repo.get_dynamic_repo/0 .","ref":"Ecto.Entity.Repo.html#get_dynamic_repo/0"},{"type":"function","title":"Ecto.Entity.Repo.in_transaction?/0","doc":"Callback implementation for Ecto.Repo.in_transaction?/0 .","ref":"Ecto.Entity.Repo.html#in_transaction?/0"},{"type":"function","title":"Ecto.Entity.Repo.insert/2","doc":"Callback implementation for Ecto.Repo.insert/2 .","ref":"Ecto.Entity.Repo.html#insert/2"},{"type":"function","title":"Ecto.Entity.Repo.insert!/2","doc":"Callback implementation for Ecto.Repo.insert!/2 .","ref":"Ecto.Entity.Repo.html#insert!/2"},{"type":"function","title":"Ecto.Entity.Repo.insert_all/3","doc":"Callback implementation for Ecto.Repo.insert_all/3 .","ref":"Ecto.Entity.Repo.html#insert_all/3"},{"type":"function","title":"Ecto.Entity.Repo.insert_or_update/2","doc":"Callback implementation for Ecto.Repo.insert_or_update/2 .","ref":"Ecto.Entity.Repo.html#insert_or_update/2"},{"type":"function","title":"Ecto.Entity.Repo.insert_or_update!/2","doc":"Callback implementation for Ecto.Repo.insert_or_update!/2 .","ref":"Ecto.Entity.Repo.html#insert_or_update!/2"},{"type":"function","title":"Ecto.Entity.Repo.load/2","doc":"Callback implementation for Ecto.Repo.load/2 .","ref":"Ecto.Entity.Repo.html#load/2"},{"type":"function","title":"Ecto.Entity.Repo.one/2","doc":"Callback implementation for Ecto.Repo.one/2 .","ref":"Ecto.Entity.Repo.html#one/2"},{"type":"function","title":"Ecto.Entity.Repo.one!/2","doc":"Callback implementation for Ecto.Repo.one!/2 .","ref":"Ecto.Entity.Repo.html#one!/2"},{"type":"function","title":"Ecto.Entity.Repo.preload/3","doc":"Callback implementation for Ecto.Repo.preload/3 .","ref":"Ecto.Entity.Repo.html#preload/3"},{"type":"function","title":"Ecto.Entity.Repo.prepare_query/3","doc":"Callback implementation for Ecto.Repo.prepare_query/3 .","ref":"Ecto.Entity.Repo.html#prepare_query/3"},{"type":"function","title":"Ecto.Entity.Repo.put_dynamic_repo/1","doc":"Callback implementation for Ecto.Repo.put_dynamic_repo/1 .","ref":"Ecto.Entity.Repo.html#put_dynamic_repo/1"},{"type":"function","title":"Ecto.Entity.Repo.query/3","doc":"A convenience function for SQL-based repositories that executes the given query. See Ecto.Adapters.SQL.query/4 for more information.","ref":"Ecto.Entity.Repo.html#query/3"},{"type":"function","title":"Ecto.Entity.Repo.query!/3","doc":"A convenience function for SQL-based repositories that executes the given query. See Ecto.Adapters.SQL.query!/4 for more information.","ref":"Ecto.Entity.Repo.html#query!/3"},{"type":"function","title":"Ecto.Entity.Repo.query_many/3","doc":"A convenience function for SQL-based repositories that executes the given multi-result query. See Ecto.Adapters.SQL.query_many/4 for more information.","ref":"Ecto.Entity.Repo.html#query_many/3"},{"type":"function","title":"Ecto.Entity.Repo.query_many!/3","doc":"A convenience function for SQL-based repositories that executes the given multi-result query. See Ecto.Adapters.SQL.query_many!/4 for more information.","ref":"Ecto.Entity.Repo.html#query_many!/3"},{"type":"function","title":"Ecto.Entity.Repo.reload/2","doc":"Callback implementation for Ecto.Repo.reload/2 .","ref":"Ecto.Entity.Repo.html#reload/2"},{"type":"function","title":"Ecto.Entity.Repo.reload!/2","doc":"Callback implementation for Ecto.Repo.reload!/2 .","ref":"Ecto.Entity.Repo.html#reload!/2"},{"type":"function","title":"Ecto.Entity.Repo.rollback/1","doc":"Callback implementation for Ecto.Repo.rollback/1 .","ref":"Ecto.Entity.Repo.html#rollback/1"},{"type":"function","title":"Ecto.Entity.Repo.start_link/1","doc":"Callback implementation for Ecto.Repo.start_link/1 .","ref":"Ecto.Entity.Repo.html#start_link/1"},{"type":"function","title":"Ecto.Entity.Repo.stop/1","doc":"Callback implementation for Ecto.Repo.stop/1 .","ref":"Ecto.Entity.Repo.html#stop/1"},{"type":"function","title":"Ecto.Entity.Repo.stream/2","doc":"Callback implementation for Ecto.Repo.stream/2 .","ref":"Ecto.Entity.Repo.html#stream/2"},{"type":"function","title":"Ecto.Entity.Repo.to_sql/2","doc":"A convenience function for SQL-based repositories that translates the given query to SQL. See Ecto.Adapters.SQL.to_sql/3 for more information.","ref":"Ecto.Entity.Repo.html#to_sql/2"},{"type":"function","title":"Ecto.Entity.Repo.transaction/2","doc":"Callback implementation for Ecto.Repo.transaction/2 .","ref":"Ecto.Entity.Repo.html#transaction/2"},{"type":"function","title":"Ecto.Entity.Repo.update/2","doc":"Callback implementation for Ecto.Repo.update/2 .","ref":"Ecto.Entity.Repo.html#update/2"},{"type":"function","title":"Ecto.Entity.Repo.update!/2","doc":"Callback implementation for Ecto.Repo.update!/2 .","ref":"Ecto.Entity.Repo.html#update!/2"},{"type":"function","title":"Ecto.Entity.Repo.update_all/3","doc":"Callback implementation for Ecto.Repo.update_all/3 .","ref":"Ecto.Entity.Repo.html#update_all/3"},{"type":"module","title":"Ecto.Entity.Update","doc":"","ref":"Ecto.Entity.Update.html"},{"type":"extras","title":"Ecto Entity","doc":"Introduction The missing Elixir Phoenix package to achieve Ecto > 80% common operations with < 20% effort. Inspired by Laravel/ Php Eloquent package, Ecto Entity includes injectable functions that makes it enjoyable to interact with your database. When using Ecto Entity, each database table has a corresponding Schema(Model) that is used to interact with that table. In addition to retrieving records from the database table, Ecto Entity allows you to insert, update, and delete records from the table as well. The goal of this package is to make it deadly simple to interact with Ecto without having to necessary write custom CRUD operations.","ref":"readme.html"},{"type":"extras","title":"Changelog for v0.1.x","doc":"","ref":"changelog.html"},{"type":"extras","title":"Changelog for v0.1.x - v0.1.4","doc":"Enhancements Removed warnings for previous matching functions. Added truncate_without_key_checks/0 to truncate a table in a MySql database. Added disable_foreign_key_checks/0 to disable foreign key checks in MySql. Added enable_foreign_key_checks/0 to enable foreign key checks in MySql. Added delete/0 to delete all schema entries. Added raw/3 for raw query functions.","ref":"changelog.html#v0-1-4"},{"type":"extras","title":"Changelog for v0.1.x - v0.1.3","doc":"Enhancements [Ecto.Entity.Create] Added create_many/1 [Ecto.Entity.Update] added update_many/2","ref":"changelog.html#v0-1-3"},{"type":"extras","title":"Getting Started","doc":"This guide is an introduction to Ecto Entity, the missing Phoenix Ecto package to achieve +80% of common operations less than 20% of effort it would normally take. Ecto Entity provides a standardized API and a set of abstractions for interacting with database tables, so that your phoenix Elixir developers can focus on what's specific to your project. In this guide, we're going to learn some basics about Ecto Entity, such as creating, reading, updating and destroying records from a database. If you want to see the code from this guide, you can view it at kamaroly/ecto_entity on GitHub . This guide will require you to have setup Entity beforehand.","ref":"getting-started.html"},{"type":"extras","title":"Getting Started - Installation","doc":"To add Entity to your application, The first step is to add Entity to your mix.exs file, which we'll do by changing the deps definition in that file to this: defp deps do [ { :ecto_entity , "~> 0.1.4" } ] end Then, to install it, you will run this command: mix deps . get","ref":"getting-started.html#installation"},{"type":"extras","title":"Getting Started - Configure Your Ecto Repo","doc":"Ecto Entity needs to know what repository to use while running database query. To do that, add config :ecto_entity, app_name: :your_app_name to your config/config.exs file. :your_app_name will be often the app configured in mix.exs under project > app . import Config # Configure your APP name so that Ecto Entity can know # What Ecto Repo to use for the entity config :ecto_entity , app_name : :your_ecto_elixir_app_name","ref":"getting-started.html#configure-your-ecto-repo"},{"type":"extras","title":"Getting Started - Adding Entity To Your Schema","doc":"To start off with, we'll need to include Entity in our existing Phoenix Schema using use Ecto.Entity in your Schema module, like the following: defmodule MyApp.Person do import Ecto.Changeset use Ecto.Schema use Ecto.Entity # Include Entity in your normal schema schema "people" do field :first_name , :string field :last_name , :string field :age , :integer end def changeset ( entity , attrs ) do entity |> cast ( attrs , [ :first_name , :last_name ] ) |> validate_required ( [ :first_name , :last_name ] ) end end NOTE: You must define a changeset/2 function to create and update your schema","ref":"getting-started.html#adding-entity-to-your-schema"},{"type":"extras","title":"Create","doc":"","ref":"create.html"},{"type":"extras","title":"Create - insert/1","doc":"create/1 and insert/1 can be used to stores create table entry. Schema module must have changeset method implementedUse the create method, which accepts an schema of attributes, creates, and inserts it into the database. The newly created schema will be returned by the create function. iex(1)> Person . create ( %{ first_name : "Hand" , last_name : "Turner" , age : 3 } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 125 , first_name : "Hand" , last_name : "Turner" , age : 3 } }","ref":"create.html#insert-1"},{"type":"extras","title":"Create - create_many/1","doc":"You may create many entries at once by passing a list of entries to create_many/1 . iex(1)> Person . create_many ( [ %{ first_name : "Parisian" , last_name : "Beier" , age : 7 } , %{ first_name : "Lang" , last_name : "Emard" , age : 3 } ] ) { :ok , %{ insert_all : { 2 , nil } } }","ref":"create.html#create_many-1"},{"type":"extras","title":"Read","doc":"","ref":"read.html"},{"type":"extras","title":"Read - find/1","doc":"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 } ]","ref":"read.html#find-1"},{"type":"extras","title":"Read - all/0","doc":"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 } ]","ref":"read.html#all-0"},{"type":"extras","title":"Read - take/1","doc":"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 } ]","ref":"read.html#take-1"},{"type":"extras","title":"Read - first/0","doc":"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 }","ref":"read.html#first-0"},{"type":"extras","title":"Read - last/0","doc":"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 }","ref":"read.html#last-0"},{"type":"extras","title":"Read - except/1","doc":"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 } ]","ref":"read.html#except-1"},{"type":"extras","title":"Update","doc":"Updates an existing entry","ref":"update.html"},{"type":"extras","title":"Update - update/2","doc":"Updates an existing record identified by an ID iex(1)> Person . update ( 1 , %{ first_name : "Kamaro" } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Kamaro" , last_name : "Yundt" , age : 7 } } Updates an existing record identified by its Schema(Model) # Find a person by id 1 iex(1)> person = Person . find ( 1 ) % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Weber" , last_name : "Ok 2" , age : 7 } iex(2)> Person . update ( person , %{ first_name : "Kamaro" } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Kamaro" , last_name : "Ok 2" , age : 7 } }","ref":"update.html#update-2"},{"type":"extras","title":"Update - update_many/1","doc":"You may update many entries at once using update_many/2 like the following iex(1)> query = Person . not_in_ids ( 1 ) # Ecto.Query < from p0 in Person , where : p0 . id not in ^ [ 1 ] > iex(2)> Person . update_many ( query , [ first_name : "Kamaro Paul" ] ) { :ok , %{ update_all : { 2 , nil } } }","ref":"update.html#update_many-1"},{"type":"extras","title":"Delete","doc":"","ref":"delete.html"},{"type":"extras","title":"Delete - delete/1","doc":"You may use delete/1 or destroy/1 to delete an existing table entry identifies by its ID. iex(1)> Person . delete ( 7 ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :deleted , "people" > , id : 7 , first_name : "Glover" , last_name : "Schimmel" , age : 2 } } delete/1 works the same as destroy/1 . It's just a preference in pronunciation. if you want to delete all table entries, you may delete/0 iex(1)> Person . destroy ( 2 ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :deleted , "people" > , id : 2 , first_name : "Ruecker" , last_name : "Lemke" , age : 0 } } You may want to delete many records at once. You can do so by passing a list of the ids like the following. When you pass a list of ids to delete or destroy, Ecto.entity return {count_of_deleted_entities, nil} iex(2)> Person . delete ( [ 3 , 6 ] ) { 2 , nil }","ref":"delete.html#delete-1"},{"type":"extras","title":"Delete - delete_except/1","doc":"You may wish to delete entries with exception using delete_except/ or destroy_except/ iex(1)> Person . delete_except ( [ 47 , 48 ] ) { 48 , nil } iex(2)> Person . all ( ) [ % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 47 , first_name : "Toy" , last_name : "Weimann" , age : 3 } , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 48 , first_name : "Wilderman" , last_name : "Treutel" , age : 9 } ]","ref":"delete.html#delete_except-1"},{"type":"extras","title":"Delete - truncate/0","doc":"You may truncate a database table by truncate/0 . truncate delete all entries and reset the table index. iex(1)> Person . truncate ( ) { :ok , % MyXQL.Result { columns : nil , connection_id : 788 , last_insert_id : 0 , num_rows : 0 , rows : nil , num_warnings : 0 } }","ref":"delete.html#truncate-0"},{"type":"extras","title":"Associations","doc":"Documentation coming soon...","ref":"association.html"},{"type":"extras","title":"Conditions","doc":"Conditions help you to retrieve data based on the specific conditions. You may do it using where condition. iex(1)> Person . where ( :first_name , "Kamaro" ) # Ecto.Query < from p0 in Person , where : p0 . first_name == ^ "Kamaro" > You may return the first entry that matches the provided where condition like the following: iex(1)> Person . where_first ( :first_name , "Dominic" ) % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 42 , first_name : "Dominic" , last_name : "Cummings" , age : 6 } Or return all entries that matches a given condition like the following: iex(1)> Person . where_all ( :age , 6 ) [ % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 9 , first_name : "Kihn" , last_name : "Graham" , age : 6 } , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 15 , first_name : "Cummerata" , last_name : "Altenwerth" , age : 6 } , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 37 , first_name : "Pollich" , last_name : "Crist" , age : 6 } , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 39 , first_name : "Daugherty" , last_name : "Mills" , age : 6 } , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 41 , first_name : "Alfonso" , last_name : "Nitzsche" , age : 6 } , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 42 , first_name : "Dominic" , last_name : "Cummings" , age : 6 } ]","ref":"conditions.html"},{"type":"extras","title":"DB","doc":"Documentation coming soon...","ref":"db.html"},{"type":"extras","title":"CRUD Cheatsheet","doc":"Assume that your schema looks like the following: defmodule MyApp.Person do import Ecto.Changeset use Ecto.Schema use Ecto.Entity # Gems brought by the Ecto Entity schema "people" do field :first_name , :string field :last_name , :string field :age , :integer end def changeset ( entity , attrs ) do entity |> cast ( attrs , [ :first_name , :last_name ] ) |> validate_required ( [ :first_name , :last_name ] ) end end","ref":"crud.html"},{"type":"extras","title":"CRUD Cheatsheet - CREATE","doc":"Create / Insert new records iex(1)> MyApp.Person . create ( %{ ... first_name : "Hand" , ... last_name : "Turner" , ... age : 3 } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 5 , first_name : "Hand" , last_name : "Turner" , age : 3 } } Create Many iex(1)> MyApp.Person . create_many ( [ ... %{ first_name : "Parisian" , last_name : "Beier" , age : 7 } , ... %{ first_name : "Lang" , last_name : "Emard" , age : 3 } ] ) { :ok , %{ insert_all : { 2 , nil } } }","ref":"crud.html#create"},{"type":"extras","title":"CRUD Cheatsheet - READ","doc":"Retrieve all entries iex(1)> MyApp.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 } ] Finding an entry by ID iex(1)> MyApp.Person . find ( 5 ) % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 5 , first_name : "Kristopher" , last_name : "Keeling" , age : 9 } Retrieve many by identifiers 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 } ] Retrieve a number of entries 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 } ]","ref":"crud.html#read"},{"type":"extras","title":"CRUD Cheatsheet - UPDATE","doc":"Update a record by identified by ID iex(1)> Person . update ( 1 , %{ first_name : "Kamaro" } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Kamaro" , last_name : "Yundt" , age : 7 } } Update Many Records at once iex(1)> query = Person . not_in_ids ( 1 ) # Ecto.Query < from p0 in Person , where : p0 . id not in ^ [ 1 ] > iex(2)> Person . update_many ( query , [ first_name : "Kamaro Paul" ] ) { :ok , %{ update_all : { 2 , nil } } } Update by entity iex(1)> person = Person . find ( 1 ) % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Weber" , last_name : "Ok 2" , age : 7 } iex(2)> Person . update ( person , %{ first_name : "Kamaro" } ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :loaded , "people" > , id : 1 , first_name : "Kamaro" , last_name : "Ok 2" , age : 7 } }","ref":"crud.html#update"},{"type":"extras","title":"CRUD Cheatsheet - DELETE","doc":"Delete an entry iex(1)> Person . delete ( 7 ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :deleted , "people" > , id : 7 , first_name : "Glover" , last_name : "Schimmel" , age : 2 } } Delete entries except record matching IDs iex(1)> Person . delete_except ( [ 47 , 48 ] ) { 48 , nil } Empty the entire table iex(1)> Person . truncate ( ) { :ok , % MyXQL.Result { columns : nil , connection_id : 788 , last_insert_id : 0 , num_rows : 0 , rows : nil , num_warnings : 0 } }","ref":"crud.html#delete"},{"type":"extras","title":"Association","doc":"Work in progress...","ref":"associations.html"}]