EctoNetwork
Ecto types to support MACADDR and Network extensions provided by Postgrex.
Although this is primarily an Ecto library, it has a hard dependency on Postgrex due to the types it is providing.
Installation
Add
ecto_networkto your list of dependencies inmix.exs:def deps do[{:ecto_network, "~> 0.1.0"}]endAdd Postgrex extensions for MACADDR and/or Network (INET, CIDR) to your Repo config.
For Phoenix, you will want to update your environment-specific config files (
config/dev.exs,config/test.exs,config/prod.exs) and add the extensions to the your Repo config.# Configure your databaseconfig :your_app, YourApp.Repo,adapter: Ecto.Adapters.Postgres,extensions: [{Postgrex.Extensions.MACADDR, nil},{Postgrex.Extensions.Network, nil}],username: "",password: "",database: "yourapp_dev",hostname: "localhost",pool_size: 10Create your migrations using the Postgres types as atoms.
def change docreate table(:your_table) doadd :ip_address, :inetadd :mac_address, :macaddradd :network, :cidrendendUse the new types in your Ecto schemas.
schema "your_table" dofield :ip_address, EctoNetwork.INETfield :mac_address, EctoNetwork.MACADDRfield :network, EctoNetwork.CIDRend