seedex v0.3.0 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 \\ [], process \\ nil) 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. The default value is[:id]data- The data to insert. It should be a list of maps. If it is not passed, a single record will be created using the function passed.process- A function to post-process each created record. It is required only ifdatais omitted.
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 \\ [], process \\ nil) View Source
Same as seed/3 but does not update the record if it already exists