Cubecto

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

Installation

Add the package to your Mixfile

defp deps do
  [{:cubecto, "~> 0.1.0"}]
end

Add Cubecto.Extension to the Postgrex types file somewhere in lib/my_app/

Postgrex.Types.define(
  MyApp.PostgrexTypes,
  [Cubecto.Extension] ++ Ecto.Adapters.Postgres.extensions()
)

Configure Repo to use custom Postgrex types in config/config.exs

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

Create the cube extension in the database

defmodule MyApp.Repo.Migrations.CreateCubeExtension do
  use Ecto.Migration

  def change do
    execute(
      "CREATE EXTENSION IF NOT EXISTS cube",
      "DROP EXTENSION IF EXISTS cube"
    )
  end
end

Usage

Add a column with the cube datatype to a table

defmodule MyApp.Repo.Migrations.CreateUser do
  use Ecto.Migration

  def change do
    create table("users") do
      add :cube, :cube
      # other fields
    end
  end
end

Use Cubecto.Type for the cube field in an Ecto.Schema module

defmodule MyApp.Accounts.User do
  use Ecto.Schema

  schema "users" do
    field :cube, Cubecto.Type
    # other fields
  end
end