Packages

An Elixir Ecto Package to Boost Your Productivity and Achieve 90% throughput in Just 10% of the Time.

Current section

Files

Jump to
entity doc dist search_items-5ABE5362.js
Raw

doc/dist/search_items-5ABE5362.js

searchNodes=[{"type":"module","title":"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 [ { :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":"Entity.html"},{"type":"module","title":"Entity.Association","doc":"","ref":"Entity.Association.html"},{"type":"function","title":"Entity.Association.all/0","doc":"Retrieves all database entries from a schema module Examples iex> SchemaModule . all ( ) [ % SchemaModule { } ] iex> SchemaModule . all ( query ) [ % SchemaModule { } ]","ref":"Entity.Association.html#all/0"},{"type":"function","title":"Entity.Association.all/1","doc":"","ref":"Entity.Association.html#all/1"},{"type":"function","title":"Entity.Association.count/0","doc":"","ref":"Entity.Association.html#count/0"},{"type":"function","title":"Entity.Association.count/1","doc":"","ref":"Entity.Association.html#count/1"},{"type":"function","title":"Entity.Association.find/1","doc":"Finds the a database entry from a schema module Examples iex> SchemaModule . find ( id ) % SchemaModule { } iex> SchemaModule . find! ( id ) % SchemaModule { }","ref":"Entity.Association.html#find/1"},{"type":"function","title":"Entity.Association.find!/1","doc":"","ref":"Entity.Association.html#find!/1"},{"type":"function","title":"Entity.Association.first/0","doc":"Retrieves the first database entry from a schema module Examples iex> SchemaModule . first ( ) % SchemaModule { } iex> SchemaModule . first ( query ) % SchemaModule { }","ref":"Entity.Association.html#first/0"},{"type":"function","title":"Entity.Association.first!/0","doc":"","ref":"Entity.Association.html#first!/0"},{"type":"function","title":"Entity.Association.first!/1","doc":"","ref":"Entity.Association.html#first!/1"},{"type":"function","title":"Entity.Association.get/0","doc":"","ref":"Entity.Association.html#get/0"},{"type":"function","title":"Entity.Association.get/1","doc":"","ref":"Entity.Association.html#get/1"},{"type":"function","title":"Entity.Association.last/0","doc":"Retrieves the last database entry from a schema module Examples iex> SchemaModule . last ( ) % SchemaModule { } iex> SchemaModule . last ( query ) % SchemaModule { }","ref":"Entity.Association.html#last/0"},{"type":"function","title":"Entity.Association.oder_by/0","doc":"","ref":"Entity.Association.html#oder_by/0"},{"type":"function","title":"Entity.Association.oder_by/1","doc":"","ref":"Entity.Association.html#oder_by/1"},{"type":"function","title":"Entity.Association.size/0","doc":"","ref":"Entity.Association.html#size/0"},{"type":"function","title":"Entity.Association.size/1","doc":"","ref":"Entity.Association.html#size/1"},{"type":"function","title":"Entity.Association.take/1","doc":"","ref":"Entity.Association.html#take/1"},{"type":"function","title":"Entity.Association.take/2","doc":"","ref":"Entity.Association.html#take/2"},{"type":"module","title":"Entity.Create","doc":"","ref":"Entity.Create.html"},{"type":"module","title":"Entity.Delete","doc":"","ref":"Entity.Delete.html"},{"type":"function","title":"Entity.Delete.all/0","doc":"Retrieves all database entries from a schema module Examples iex> SchemaModule . all ( ) [ % SchemaModule { } ] iex> SchemaModule . all ( query ) [ % SchemaModule { } ]","ref":"Entity.Delete.html#all/0"},{"type":"function","title":"Entity.Delete.all/1","doc":"","ref":"Entity.Delete.html#all/1"},{"type":"function","title":"Entity.Delete.count/0","doc":"","ref":"Entity.Delete.html#count/0"},{"type":"function","title":"Entity.Delete.count/1","doc":"","ref":"Entity.Delete.html#count/1"},{"type":"function","title":"Entity.Delete.find/1","doc":"Finds the a database entry from a schema module Examples iex> SchemaModule . find ( id ) % SchemaModule { } iex> SchemaModule . find! ( id ) % SchemaModule { }","ref":"Entity.Delete.html#find/1"},{"type":"function","title":"Entity.Delete.find!/1","doc":"","ref":"Entity.Delete.html#find!/1"},{"type":"function","title":"Entity.Delete.first/0","doc":"Retrieves the first database entry from a schema module Examples iex> SchemaModule . first ( ) % SchemaModule { } iex> SchemaModule . first ( query ) % SchemaModule { }","ref":"Entity.Delete.html#first/0"},{"type":"function","title":"Entity.Delete.first!/0","doc":"","ref":"Entity.Delete.html#first!/0"},{"type":"function","title":"Entity.Delete.first!/1","doc":"","ref":"Entity.Delete.html#first!/1"},{"type":"function","title":"Entity.Delete.get/0","doc":"","ref":"Entity.Delete.html#get/0"},{"type":"function","title":"Entity.Delete.get/1","doc":"","ref":"Entity.Delete.html#get/1"},{"type":"function","title":"Entity.Delete.last/0","doc":"Retrieves the last database entry from a schema module Examples iex> SchemaModule . last ( ) % SchemaModule { } iex> SchemaModule . last ( query ) % SchemaModule { }","ref":"Entity.Delete.html#last/0"},{"type":"function","title":"Entity.Delete.oder_by/0","doc":"","ref":"Entity.Delete.html#oder_by/0"},{"type":"function","title":"Entity.Delete.oder_by/1","doc":"","ref":"Entity.Delete.html#oder_by/1"},{"type":"function","title":"Entity.Delete.size/0","doc":"","ref":"Entity.Delete.html#size/0"},{"type":"function","title":"Entity.Delete.size/1","doc":"","ref":"Entity.Delete.html#size/1"},{"type":"function","title":"Entity.Delete.take/1","doc":"","ref":"Entity.Delete.html#take/1"},{"type":"function","title":"Entity.Delete.take/2","doc":"","ref":"Entity.Delete.html#take/2"},{"type":"module","title":"Entity.Helpers","doc":"","ref":"Entity.Helpers.html"},{"type":"function","title":"Entity.Helpers.app_name/0","doc":"Get the repo to use","ref":"Entity.Helpers.html#app_name/0"},{"type":"function","title":"Entity.Helpers.get_repo/0","doc":"","ref":"Entity.Helpers.html#get_repo/0"},{"type":"module","title":"Entity.Read","doc":"","ref":"Entity.Read.html"},{"type":"module","title":"Entity.Repo","doc":"","ref":"Entity.Repo.html"},{"type":"function","title":"Entity.Repo.aggregate/3","doc":"Callback implementation for Ecto.Repo.aggregate/3 .","ref":"Entity.Repo.html#aggregate/3"},{"type":"function","title":"Entity.Repo.aggregate/4","doc":"Callback implementation for Ecto.Repo.aggregate/4 .","ref":"Entity.Repo.html#aggregate/4"},{"type":"function","title":"Entity.Repo.all/2","doc":"Callback implementation for Ecto.Repo.all/2 .","ref":"Entity.Repo.html#all/2"},{"type":"function","title":"Entity.Repo.checked_out?/0","doc":"Callback implementation for Ecto.Repo.checked_out?/0 .","ref":"Entity.Repo.html#checked_out?/0"},{"type":"function","title":"Entity.Repo.checkout/2","doc":"Callback implementation for Ecto.Repo.checkout/2 .","ref":"Entity.Repo.html#checkout/2"},{"type":"function","title":"Entity.Repo.child_spec/1","doc":"","ref":"Entity.Repo.html#child_spec/1"},{"type":"function","title":"Entity.Repo.config/0","doc":"Callback implementation for Ecto.Repo.config/0 .","ref":"Entity.Repo.html#config/0"},{"type":"function","title":"Entity.Repo.default_options/1","doc":"Callback implementation for Ecto.Repo.default_options/1 .","ref":"Entity.Repo.html#default_options/1"},{"type":"function","title":"Entity.Repo.delete/2","doc":"Callback implementation for Ecto.Repo.delete/2 .","ref":"Entity.Repo.html#delete/2"},{"type":"function","title":"Entity.Repo.delete!/2","doc":"Callback implementation for Ecto.Repo.delete!/2 .","ref":"Entity.Repo.html#delete!/2"},{"type":"function","title":"Entity.Repo.delete_all/2","doc":"Callback implementation for Ecto.Repo.delete_all/2 .","ref":"Entity.Repo.html#delete_all/2"},{"type":"function","title":"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":"Entity.Repo.html#disconnect_all/2"},{"type":"function","title":"Entity.Repo.exists?/2","doc":"Callback implementation for Ecto.Repo.exists?/2 .","ref":"Entity.Repo.html#exists?/2"},{"type":"function","title":"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":"Entity.Repo.html#explain/3"},{"type":"function","title":"Entity.Repo.get/3","doc":"Callback implementation for Ecto.Repo.get/3 .","ref":"Entity.Repo.html#get/3"},{"type":"function","title":"Entity.Repo.get!/3","doc":"Callback implementation for Ecto.Repo.get!/3 .","ref":"Entity.Repo.html#get!/3"},{"type":"function","title":"Entity.Repo.get_by/3","doc":"Callback implementation for Ecto.Repo.get_by/3 .","ref":"Entity.Repo.html#get_by/3"},{"type":"function","title":"Entity.Repo.get_by!/3","doc":"Callback implementation for Ecto.Repo.get_by!/3 .","ref":"Entity.Repo.html#get_by!/3"},{"type":"function","title":"Entity.Repo.get_dynamic_repo/0","doc":"Callback implementation for Ecto.Repo.get_dynamic_repo/0 .","ref":"Entity.Repo.html#get_dynamic_repo/0"},{"type":"function","title":"Entity.Repo.in_transaction?/0","doc":"Callback implementation for Ecto.Repo.in_transaction?/0 .","ref":"Entity.Repo.html#in_transaction?/0"},{"type":"function","title":"Entity.Repo.insert/2","doc":"Callback implementation for Ecto.Repo.insert/2 .","ref":"Entity.Repo.html#insert/2"},{"type":"function","title":"Entity.Repo.insert!/2","doc":"Callback implementation for Ecto.Repo.insert!/2 .","ref":"Entity.Repo.html#insert!/2"},{"type":"function","title":"Entity.Repo.insert_all/3","doc":"Callback implementation for Ecto.Repo.insert_all/3 .","ref":"Entity.Repo.html#insert_all/3"},{"type":"function","title":"Entity.Repo.insert_or_update/2","doc":"Callback implementation for Ecto.Repo.insert_or_update/2 .","ref":"Entity.Repo.html#insert_or_update/2"},{"type":"function","title":"Entity.Repo.insert_or_update!/2","doc":"Callback implementation for Ecto.Repo.insert_or_update!/2 .","ref":"Entity.Repo.html#insert_or_update!/2"},{"type":"function","title":"Entity.Repo.load/2","doc":"Callback implementation for Ecto.Repo.load/2 .","ref":"Entity.Repo.html#load/2"},{"type":"function","title":"Entity.Repo.one/2","doc":"Callback implementation for Ecto.Repo.one/2 .","ref":"Entity.Repo.html#one/2"},{"type":"function","title":"Entity.Repo.one!/2","doc":"Callback implementation for Ecto.Repo.one!/2 .","ref":"Entity.Repo.html#one!/2"},{"type":"function","title":"Entity.Repo.preload/3","doc":"Callback implementation for Ecto.Repo.preload/3 .","ref":"Entity.Repo.html#preload/3"},{"type":"function","title":"Entity.Repo.prepare_query/3","doc":"Callback implementation for Ecto.Repo.prepare_query/3 .","ref":"Entity.Repo.html#prepare_query/3"},{"type":"function","title":"Entity.Repo.put_dynamic_repo/1","doc":"Callback implementation for Ecto.Repo.put_dynamic_repo/1 .","ref":"Entity.Repo.html#put_dynamic_repo/1"},{"type":"function","title":"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":"Entity.Repo.html#query/3"},{"type":"function","title":"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":"Entity.Repo.html#query!/3"},{"type":"function","title":"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":"Entity.Repo.html#query_many/3"},{"type":"function","title":"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":"Entity.Repo.html#query_many!/3"},{"type":"function","title":"Entity.Repo.reload/2","doc":"Callback implementation for Ecto.Repo.reload/2 .","ref":"Entity.Repo.html#reload/2"},{"type":"function","title":"Entity.Repo.reload!/2","doc":"Callback implementation for Ecto.Repo.reload!/2 .","ref":"Entity.Repo.html#reload!/2"},{"type":"function","title":"Entity.Repo.rollback/1","doc":"Callback implementation for Ecto.Repo.rollback/1 .","ref":"Entity.Repo.html#rollback/1"},{"type":"function","title":"Entity.Repo.start_link/1","doc":"Callback implementation for Ecto.Repo.start_link/1 .","ref":"Entity.Repo.html#start_link/1"},{"type":"function","title":"Entity.Repo.stop/1","doc":"Callback implementation for Ecto.Repo.stop/1 .","ref":"Entity.Repo.html#stop/1"},{"type":"function","title":"Entity.Repo.stream/2","doc":"Callback implementation for Ecto.Repo.stream/2 .","ref":"Entity.Repo.html#stream/2"},{"type":"function","title":"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":"Entity.Repo.html#to_sql/2"},{"type":"function","title":"Entity.Repo.transaction/2","doc":"Callback implementation for Ecto.Repo.transaction/2 .","ref":"Entity.Repo.html#transaction/2"},{"type":"function","title":"Entity.Repo.update/2","doc":"Callback implementation for Ecto.Repo.update/2 .","ref":"Entity.Repo.html#update/2"},{"type":"function","title":"Entity.Repo.update!/2","doc":"Callback implementation for Ecto.Repo.update!/2 .","ref":"Entity.Repo.html#update!/2"},{"type":"function","title":"Entity.Repo.update_all/3","doc":"Callback implementation for Ecto.Repo.update_all/3 .","ref":"Entity.Repo.html#update_all/3"},{"type":"module","title":"Entity.Update","doc":"","ref":"Entity.Update.html"},{"type":"function","title":"Entity.Update.all/0","doc":"Retrieves all database entries from a schema module Examples iex> SchemaModule . all ( ) [ % SchemaModule { } ] iex> SchemaModule . all ( query ) [ % SchemaModule { } ]","ref":"Entity.Update.html#all/0"},{"type":"function","title":"Entity.Update.all/1","doc":"","ref":"Entity.Update.html#all/1"},{"type":"function","title":"Entity.Update.count/0","doc":"","ref":"Entity.Update.html#count/0"},{"type":"function","title":"Entity.Update.count/1","doc":"","ref":"Entity.Update.html#count/1"},{"type":"function","title":"Entity.Update.find/1","doc":"Finds the a database entry from a schema module Examples iex> SchemaModule . find ( id ) % SchemaModule { } iex> SchemaModule . find! ( id ) % SchemaModule { }","ref":"Entity.Update.html#find/1"},{"type":"function","title":"Entity.Update.find!/1","doc":"","ref":"Entity.Update.html#find!/1"},{"type":"function","title":"Entity.Update.first/0","doc":"Retrieves the first database entry from a schema module Examples iex> SchemaModule . first ( ) % SchemaModule { } iex> SchemaModule . first ( query ) % SchemaModule { }","ref":"Entity.Update.html#first/0"},{"type":"function","title":"Entity.Update.first!/0","doc":"","ref":"Entity.Update.html#first!/0"},{"type":"function","title":"Entity.Update.first!/1","doc":"","ref":"Entity.Update.html#first!/1"},{"type":"function","title":"Entity.Update.get/0","doc":"","ref":"Entity.Update.html#get/0"},{"type":"function","title":"Entity.Update.get/1","doc":"","ref":"Entity.Update.html#get/1"},{"type":"function","title":"Entity.Update.last/0","doc":"Retrieves the last database entry from a schema module Examples iex> SchemaModule . last ( ) % SchemaModule { } iex> SchemaModule . last ( query ) % SchemaModule { }","ref":"Entity.Update.html#last/0"},{"type":"function","title":"Entity.Update.oder_by/0","doc":"","ref":"Entity.Update.html#oder_by/0"},{"type":"function","title":"Entity.Update.oder_by/1","doc":"","ref":"Entity.Update.html#oder_by/1"},{"type":"function","title":"Entity.Update.size/0","doc":"","ref":"Entity.Update.html#size/0"},{"type":"function","title":"Entity.Update.size/1","doc":"","ref":"Entity.Update.html#size/1"},{"type":"function","title":"Entity.Update.take/1","doc":"","ref":"Entity.Update.html#take/1"},{"type":"function","title":"Entity.Update.take/2","doc":"","ref":"Entity.Update.html#take/2"},{"type":"extras","title":"Entity","doc":"","ref":"readme.html"},{"type":"extras","title":"Entity - Introduction","doc":"The missing Elixir Phoenix package to achieve Ecto > 80% common operations with < 20% effort. 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.","ref":"readme.html#introduction"},{"type":"extras","title":"Entity - Getting Started","doc":"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. 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 [ { :entity , "~> 0.1.0" } ] end Then, to install it, you will run this command: mix deps . get Configure Your Ecto Repo Ecto Entity needs to know what repository to use while running database query. To do that, add config :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 :entity , app_name : :your_ecto_elixir_app_name Adding Entity To Your Schema To start off with, we'll need to include Entity in our existing Phoenix Schema using use Entity in your Schema module, like the following: defmodule MyApp.Person do import Ecto.Changeset use Ecto.Schema use 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","ref":"readme.html#getting-started"},{"type":"extras","title":"Entity - Create","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> 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":"readme.html#create"},{"type":"extras","title":"Entity - Read","doc":"","ref":"readme.html#read"},{"type":"extras","title":"Entity - find/1","doc":"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 }","ref":"readme.html#find-1"},{"type":"extras","title":"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":"Entity - take/1","doc":"Returns 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 } ]","ref":"readme.html#take-1"},{"type":"extras","title":"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":"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 } iex(2)> UPDATE Updates an existing entry","ref":"readme.html#last-0"},{"type":"extras","title":"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":"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 } } destroy/1 iex(3)> Person . destroy ( 2 ) { :ok , % Person { __meta__ : # Ecto.Schema.Metadata < :deleted , "people" > , id : 2 , first_name : "Ruecker" , last_name : "Lemke" , age : 0 } } truncate 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 } } iex(2)>","ref":"readme.html#updates-2"}]