seedex v0.2.1 Seedex View Source
Functions to populate database with seed data.
Link to this section Summary
Link to this section Functions
Link to this function
seed(module, constraints \\ [:id], data) View Source
seed/3
inserts data in the given table
Arguments
module
- The module containing the Ecto schema.contraints
- The fields used to idenfity a record. The record will be updated if a record with matching fields already exist.data
- The data to insert. It can either be a list of maps, each containing a record or a function which takes astruct
as input and output.
Examples
seed MyApp.Point, [:x, :y], fn point ->
point
|> Map.put(:x, 4)
|> Map.put(:y, 7)
|> Map.put(:name, "Home")
end
seed MyApp.User, [
%{name: "Daniel", age: 26},
%{name: "Ai", age: 24}
]
Link to this function
seed_once(module, constraints \\ [:id], data) View Source
Same as seed/3
but does not update the record if it already exists