Blink

Fast bulk data insertion for Ecto and PostgreSQL.

Installation

Add blink to your list of dependencies in mix.exs:

def deps do
[
{:blink, "~> 0.6.0"}
]
end

Example

defmodule MyApp.Seeder do
use Blink
def call do
new()
|> with_table("users")
|> with_table("posts")
|> run(MyApp.Repo)
end
def table(_seeder, "users") do
for i <- 1..1000 do
%{
id: i,
name: "User #{i}",
email: "user#{i}@example.com",
inserted_at: ~U[2024-01-01 00:00:00Z],
updated_at: ~U[2024-01-01 00:00:00Z]
}
end
end
def table(seeder, "posts") do
Enum.flat_map(seeder.tables["users"], fn user ->
for i <- 1..5 do
%{
id: (user.id - 1) * 5 + i,
title: "Post #{i}",
user_id: user.id,
inserted_at: ~U[2024-01-01 00:00:00Z],
updated_at: ~U[2024-01-01 00:00:00Z]
}
end
end)
end
end
# Inserts 1,000 users and 5,000 posts
MyApp.Seeder.call()

Features

Documentation

See the getting started guide and full documentation for more.

Requirements

License

MIT - see LICENSE for details.