Postgrex.Extension and Ecto.Type for PostgreSQL isn module
Go to file
Martin Frost af4bbd723a Migrate from Mix.Config to Config 2022-05-10 22:57:21 +02:00
config Migrate from Mix.Config to Config 2022-05-10 22:57:21 +02:00
lib Mix format everything 2018-01-26 17:55:15 +01:00
test Mix format everything 2018-01-26 17:55:15 +01:00
.formatter.exs Add .formatter.exs 2018-01-26 17:55:08 +01:00
.gitignore Ignore emacs *~ temp files 2016-01-10 12:46:28 +01:00
.tool-versions Add .tool-versions file 2022-05-10 22:57:21 +02:00
README.md ISN 2.0: Support Postgrex 0.13 and Ecto 2.1 2017-04-21 19:21:29 +02:00
mix.exs version 2.0.1 2018-01-26 17:59:55 +01:00
mix.lock Update ex_doc dependency 2017-04-21 13:10:54 +02:00

README.md

ISN

Build Status

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

Usage

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, read_after_writes: true
    # other fields
  end
end

Installation

Add the package to your Mixfile

defp deps do
  [{:isn, "~> 2.0"}]
end

Add the isn extension to your database

mix do isn.gen.migration, ecto.migrate

In lib/ directory create a file with the following content:

Postgrex.Types.define(
  MyApp.PostgrexTypes,
  [ISN] ++ Ecto.Adapters.Postgres.extensions(),
  json: Poison
)

Add the following lines in conig.exs:

config :my_app, MyApp.Repo,
  types: MyApp.PostgrexTypes

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