Postgrex.Extension and Ecto.Type for PostgreSQL isn module
Go to file
Martin Frost f076bd5ec5 Flesh out readme to actually be useful 2015-05-27 19:13:05 +02:00
config WIP 2015-05-05 22:15:40 +02:00
lib v0.1: Flesh out library with all types in isn 2015-05-27 18:22:51 +02:00
test v0.1: Flesh out library with all types in isn 2015-05-27 18:22:51 +02:00
.gitignore WIP 2015-05-05 22:15:40 +02:00
README.md Flesh out readme to actually be useful 2015-05-27 19:13:05 +02:00
mix.exs v0.1: Flesh out library with all types in isn 2015-05-27 18:22:51 +02:00
mix.lock WIP 2015-05-05 22:15:40 +02:00

README.md

Isn

Isn adds a Postgrex.Extension and Ecto.Type definitions for the datatypes defined in the isn PostgreSQL module.

Usage

  1. Add the package to your Mixfile:
defp deps do
  [{:isn, "~> 0.1"}]
end
  1. Register the postgrex extension
Postgrex.Connection.start_link(
  database: "isn_test",
  extensions: [{Isn, {}}])
  1. Start using all of the isn goodness in your project.

Examples

Here are a few small snippets for how to use these types in various contexts. I have extracted these snippets from a phoenix project, so if you want to use them in something else, you might have to modify them a bit.

Ecto migrations

defmodule MyApp.Repo.Migrations.CreateBook do
  use Ecto.Migration

  def change do
    create table(:books) do
      add :isbn, :isbn13
      # other fields
    end
  end
end

Ecto Models

defmodule MyApp.Book do
  use MyApp.Web, :model

  schema "books" do
    field :isbn, Isn.ISBN13
    # other fields
  end
end

Defined types

Isn adds the following ecto and corresponding postgrex types:

Ecto.Type Postgrex type
Isn.ISBN :isbn
Isn.ISBN13 :isbn13
Isn.ISMN :ismn
Isn.ISMN13 :ismn13
Isn.ISSN :issn
Isn.ISSN13 :issn13
Isn.EAN13 :ean13
Isn.UPC :upc