Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Frost/isn
Postgrex.Extension and Ecto.Type for PostgreSQL isn module
https://github.com/Frost/isn
Last synced: about 1 month ago
JSON representation
Postgrex.Extension and Ecto.Type for PostgreSQL isn module
- Host: GitHub
- URL: https://github.com/Frost/isn
- Owner: Frost
- Created: 2015-05-05T20:27:02.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-04-11T14:45:23.000Z (8 months ago)
- Last Synced: 2024-04-11T17:15:54.711Z (8 months ago)
- Language: Elixir
- Size: 141 KB
- Stars: 8
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Ecto types for the postgreSQL isn extension. (ORM and Datamapping)
- fucking-awesome-elixir - isn - Ecto types for the postgreSQL isn extension. (ORM and Datamapping)
- awesome-elixir - isn - Ecto types for the postgreSQL isn extension. (ORM and Datamapping)
README
# ISN
[![Build Status][4]][5]
ISN adds a [`Postgrex.Extension`][1] and [`Ecto.Type`][2] definitions
for the datatypes defined in the [`isn`][3] PostgreSQL module.## Usage
### Ecto migrations
```elixir
defmodule MyApp.Repo.Migrations.CreateBook do
use Ecto.Migrationdef change do
create table(:books) do
add :isbn, :isbn13
# other fields
end
end
end
```### Ecto Models
```elixir
defmodule MyApp.Book do
use MyApp.Web, :modelschema "books" do
field :isbn, ISN.ISBN13, read_after_writes: true
# other fields
end
end
```## Installation
**Add the package to your Mixfile**
```elixir
defp deps do
[{:isn, "~> 3.0"}]
end
```**Add the isn extension to your database**
mix do isn.gen.migration, ecto.migrate
**Add a lib/postgrex_types.ex file with the following content:**
```elixir
Postgrex.Types.define(MyApp.PostgrexTypes, [ISN], [])
```**Add the following lines in config.exs:**
```elixir
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`[1]: http://hexdocs.pm/postgrex/Postgrex.Extension.html
[2]: http://hexdocs.pm/ecto/Ecto.Type.html
[3]: http://www.postgresql.org/docs/9.4/static/isn.html
[4]: https://semaphoreci.com/api/v1/projects/be7c4c34-c49e-45c7-9320-3fcc4f7f476a/458429/badge.svg
[5]: https://semaphoreci.com/frost/isn