Postgrex.Extension and Ecto.Type for PostgreSQL isn module
Go to file
Martin Frost e38b0b6b79 Modify test_helper to work with Semaphore CI 2015-06-18 18:00:09 +02:00
config WIP 2015-05-05 22:15:40 +02:00
lib Explicitly `unquote(isn_type)` in Isn.Base 2015-06-10 08:24:24 +02:00
test Modify test_helper to work with Semaphore CI 2015-06-18 18:00:09 +02:00
.gitignore Added better documentation. 2015-05-27 19:38:26 +02:00
README.md Added better documentation. 2015-05-27 19:38:26 +02:00
mix.exs Add eh for documentation lookup 2015-06-02 08:03:03 +02:00
mix.lock Add eh for documentation lookup 2015-06-02 08:03:03 +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. Add the isn extension to your database
{:ok, pid} = Postgrex.Connection.start_link(
  hostname: "localhost",
  database: "isn_test"
)
Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
  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