Blink.Store (blink v0.4.1)
View SourceThe central data structure and operations for the Blink seeding pipeline.
This module provides the Store struct and functions for building and
inserting seed data into your database.
A Store holds:
:tables— data that will be inserted into the database.:table_order- the order in which tables were added, used to ensure inserts respect foreign key constraints.:context— auxiliary data available while constructing theStore, and will not be inserted into the database.
Summary
Functions
Adds context to the store by calling the provided builder function.
Adds a table to the store by calling the provided builder function.
Inserts all table records from a Store into the given repository. Iterates over the tables in order when seeding the database.
Creates an empty Store.
Types
Functions
Adds context to the store by calling the provided builder function.
The builder function should take a store and key and return the context data.
Adds a table to the store by calling the provided builder function.
The builder function should take a store and table name and return a list of maps representing the table data.
@spec insert(store :: t(), repo :: Ecto.Repo.t(), opts :: Keyword.t()) :: {:ok, any()} | {:error, any()}
Inserts all table records from a Store into the given repository. Iterates over the tables in order when seeding the database.
The repo parameter must be a module that implements the Ecto.Repo behaviour and is configured with a Postgres adapter (e.g., Ecto.Adapters.Postgres).
Data stored in the Store's context is ignored.
@spec new() :: empty()
Creates an empty Store.
Example
iex> Blink.Store.new()
%Blink.Store{tables: %{}, table_order: [], context: %{}}