Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seaneshbaugh/exseed
An Elixir library that provides a simple DSL for seeding databases through Ecto.
https://github.com/seaneshbaugh/exseed
Last synced: 3 months ago
JSON representation
An Elixir library that provides a simple DSL for seeding databases through Ecto.
- Host: GitHub
- URL: https://github.com/seaneshbaugh/exseed
- Owner: seaneshbaugh
- Created: 2015-05-07T19:29:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T21:47:46.000Z (over 4 years ago)
- Last Synced: 2024-10-09T03:41:21.613Z (4 months ago)
- Language: Elixir
- Size: 18.6 KB
- Stars: 17
- Watchers: 3
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - An Elixir library that provides a simple DSL for seeding databases through Ecto. (ORM and Datamapping)
- fucking-awesome-elixir - exseed - An Elixir library that provides a simple DSL for seeding databases through Ecto. (ORM and Datamapping)
- awesome-elixir - exseed - An Elixir library that provides a simple DSL for seeding databases through Ecto. (ORM and Datamapping)
README
# Exseed
An Elixir library that provides a simple DSL for seeding databases through Ecto.
Inspired largely by [seed-fu](https://github.com/mbleigh/seed-fu).
## Installation
In your project's `mix.exs` add the following:
```elixir
defp deps do
{:exseed, "~> 0.0.3"}
end
```and then run `mix deps.get`.
## Setup
In `config/config.exs` add:
```elixir
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`:
```elixir
import Exseedseed YourApplication.Post do
id 1title "First Post!"
body "Hello, world!"
endseed YourApplication.Post do
id 2title "Second Post"
{{year, month, day}, {hour, minute, second}} = :calendar.universal_time()
body "This entry was seeded at #{year}-#{month}-#{day} #{hour}:#{minute}:#{second}."
end
```