seedex v0.1.0 Seedex
Functions to populate database with seed data.
Summary
Functions
Specs
seed(module :: atom, constraints :: [atom], data :: (() -> :ok) | [map]) :: :ok
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}
]
Specs
seed_once(module :: atom, constraints :: [atom], data :: (() -> :ok) | [map]) :: :ok
Same as seed/3
but does not update the record if it already exists