Skip to content

An Elixir library that provides a simple DSL for seeding databases through Ecto.

Notifications You must be signed in to change notification settings

seaneshbaugh/exseed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exseed

An Elixir library that provides a simple DSL for seeding databases through Ecto.

Inspired largely by seed-fu.

Installation

In your project's mix.exs add the following:

    defp deps do
      {:exseed, "~> 0.0.3"}
    end

and then run mix deps.get.

Setup

In config/config.exs add:

    config :exseed, :repo, YourApplication.Repo

Usage

Exseed provides a seed macro which expects an Ecto model and a block. Inside the block the fields on your model will be available as functions which will set the value for the field for that record.

By default Exseed will look in your project's priv/repo/seeds/ directory for seed files to load. Let's say you have a model named Post, you could put the following in priv/repo/seeds/posts.exs:

    import Exseed

    seed YourApplication.Post do
      id 1

      title "First Post!"

      body "Hello, world!"
    end

    seed YourApplication.Post do
      id 2

      title "Second Post"

      {{year, month, day}, {hour, minute, second}} = :calendar.universal_time()

      body "This entry was seeded at #{year}-#{month}-#{day} #{hour}:#{minute}:#{second}."
    end

About

An Elixir library that provides a simple DSL for seeding databases through Ecto.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages