Current section
Files
Jump to
Current section
Files
doc/dist/search_items-4ABB903B.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.Conditions","doc":"","ref":"Ecto.Entity.Conditions.html"},{"type":"module","title":"Ecto.Entity.Create","doc":"","ref":"Ecto.Entity.Create.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":"function","title":"Ecto.Entity.Helpers.app_name/0","doc":"Get the repo to use","ref":"Ecto.Entity.Helpers.html#app_name/0"},{"type":"function","title":"Ecto.Entity.Helpers.get_repo/0","doc":"","ref":"Ecto.Entity.Helpers.html#get_repo/0"},{"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. Getting Started 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. Installation 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","ref":"readme.html"},{"type":"extras","title":"Ecto Entity - 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":"readme.html#configure-your-ecto-repo"},{"type":"extras","title":"Ecto Entity - 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 CREATE 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> 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 } } READ","ref":"readme.html#adding-entity-to-your-schema"},{"type":"extras","title":"Ecto Entity - 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 Person . find ( [ 1 , 2 , 3 ] )","ref":"readme.html#find-1"},{"type":"extras","title":"Ecto Entity - all/0","doc":"Returns 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 } ]","ref":"readme.html#all-0"},{"type":"extras","title":"Ecto Entity - take/1","doc":"or take a specific 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 } ]","ref":"readme.html#take-1"},{"type":"extras","title":"Ecto Entity - 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 } iex(2)>","ref":"readme.html#first-0"},{"type":"extras","title":"Ecto Entity - 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":"readme.html#last-0"},{"type":"extras","title":"Ecto Entity - 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 } ] UPDATE Updates an existing entry","ref":"readme.html#except-1"},{"type":"extras","title":"Ecto Entity - update/2","doc":"Updates an existing record identified by an 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 } }","ref":"readme.html#update-2"},{"type":"extras","title":"Ecto Entity - updates/2","doc":"Updates an existing record identified by its Schema(Model) 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 } } DELETE delete/1 You may use delete/1 or destroy/1 to delete an existing table entry identifies by its ID. iex(2)> 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. iex(3)> 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 } delete_except/1 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":"readme.html#updates-2"},{"type":"extras","title":"Ecto Entity - truncate","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 } } CONDITIONS Conditions help you to retrieve data based on the table fields. 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(8)> 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":"readme.html#truncate"}]