| 
									
										
										
										
											2016-01-10 11:12:38 +00:00
										 |  |  | # ISN
 | 
					
						
							| 
									
										
										
										
											2015-05-05 20:15:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-09 10:23:23 +00:00
										 |  |  | [![Build Status][4]][5] | 
					
						
							| 
									
										
										
										
											2015-06-18 16:02:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 11:12:38 +00:00
										 |  |  | ISN adds a [`Postgrex.Extension`][1] and [`Ecto.Type`][2] definitions | 
					
						
							| 
									
										
										
										
											2015-05-27 17:13:05 +00:00
										 |  |  | for the datatypes defined in the [`isn`][3] PostgreSQL module. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Usage
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### Ecto migrations
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```elixir | 
					
						
							|  |  |  | 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
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```elixir | 
					
						
							|  |  |  | defmodule MyApp.Book do | 
					
						
							|  |  |  |   use MyApp.Web, :model | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   schema "books" do | 
					
						
							| 
									
										
										
										
											2017-04-21 10:17:10 +00:00
										 |  |  |     field :isbn, ISN.ISBN13, read_after_writes: true | 
					
						
							| 
									
										
										
										
											2015-05-27 17:13:05 +00:00
										 |  |  |     # other fields | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 11:39:44 +00:00
										 |  |  | ## Installation
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 12:15:24 +00:00
										 |  |  | **Add the package to your Mixfile** | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```elixir | 
					
						
							|  |  |  | defp deps do | 
					
						
							| 
									
										
										
										
											2017-04-21 11:12:02 +00:00
										 |  |  |   [{:isn, "~> 2.0"}] | 
					
						
							| 
									
										
										
										
											2016-01-10 12:15:24 +00:00
										 |  |  | end | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | **Add the isn extension to your database** | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mix do isn.gen.migration, ecto.migrate | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 10:17:10 +00:00
										 |  |  | **In lib/ directory create a file with the following content:** | 
					
						
							| 
									
										
										
										
											2016-01-10 12:15:24 +00:00
										 |  |  | ```elixir | 
					
						
							| 
									
										
										
										
											2017-04-21 10:17:10 +00:00
										 |  |  | Postgrex.Types.define( | 
					
						
							|  |  |  |   MyApp.PostgrexTypes, | 
					
						
							|  |  |  |   [ISN] ++ Ecto.Adapters.Postgres.extensions(), | 
					
						
							|  |  |  |   json: Poison | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | **Add the following lines in conig.exs:** | 
					
						
							|  |  |  | ```elixir | 
					
						
							|  |  |  | config :my_app, MyApp.Repo, | 
					
						
							|  |  |  |   types: MyApp.PostgrexTypes | 
					
						
							| 
									
										
										
										
											2016-01-10 12:15:24 +00:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2016-01-10 11:39:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-27 17:13:05 +00:00
										 |  |  | ## Defined types
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 11:12:38 +00:00
										 |  |  | `ISN` adds the following ecto and corresponding postgrex types: | 
					
						
							| 
									
										
										
										
											2015-05-27 17:13:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Ecto.Type    | Postgrex type | 
					
						
							|  |  |  | -------------|-------------- | 
					
						
							| 
									
										
										
										
											2016-01-10 11:12:38 +00:00
										 |  |  | `ISN.ISBN`   | `:isbn` | 
					
						
							|  |  |  | `ISN.ISBN13` | `:isbn13` | 
					
						
							|  |  |  | `ISN.ISMN`   | `:ismn` | 
					
						
							|  |  |  | `ISN.ISMN13` | `:ismn13` | 
					
						
							|  |  |  | `ISN.ISSN`   | `:issn` | 
					
						
							|  |  |  | `ISN.ISSN13` | `:issn13` | 
					
						
							|  |  |  | `ISN.EAN13`  | `:ean13` | 
					
						
							|  |  |  | `ISN.UPC`    | `:upc` | 
					
						
							| 
									
										
										
										
											2015-05-27 17:13:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | [1]: http://hexdocs.pm/postgrex/Postgrex.Extension.html | 
					
						
							| 
									
										
										
										
											2016-01-09 10:23:23 +00:00
										 |  |  | [2]: http://hexdocs.pm/ecto/Ecto.Type.html | 
					
						
							| 
									
										
										
										
											2015-05-27 17:13:05 +00:00
										 |  |  | [3]: http://www.postgresql.org/docs/9.4/static/isn.html | 
					
						
							| 
									
										
										
										
											2016-01-09 10:23:23 +00:00
										 |  |  | [4]: https://semaphoreci.com/api/v1/projects/be7c4c34-c49e-45c7-9320-3fcc4f7f476a/458429/badge.svg | 
					
						
							| 
									
										
										
										
											2017-04-21 10:17:10 +00:00
										 |  |  | [5]: https://semaphoreci.com/frost/isn |