Skip to content

emoragaf/ecto_postgres_json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EctoPostgresJson

Hex Version Hex Docs Total Download License Last Updated

Ecto utilities to work with PostgreSQL JSONb columns.

Indexes

Provides a json_index/3 function to use alongside Ecto migrations that handles the creation of key and column GIN based indexes for JSONb columns.

Installation

The package can be installed by adding :ecto_postgres_json to deps/0 function in mix.exs:

{:ecto_postgres_json, "~> 0.1.0"},

Usage

Import the utility module in your migration:

defmodule MyApp.Repo.Migrations.CreatePosts do
  use Ecto.Migration
  import EctoPostgresJson.Index
...
end

Define indexes using EctoPostgresJson.Index.json_index/3:

defmodule MyApp.Repo.Migrations.CreatePosts do
  ...
  def change do
    create table(:posts) do
      add :name, :string
      add :payload, :map

      timestamps()
    end
    create json_index(:posts, :payload)
    create json_index(:posts, ["payload", "tags"], name: :post_tags_index)
  end
end

Copyright and License

Copyright (c) 2022 Eduardo Moraga

This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE.md file for more details.

About

Postgres JSONb utils for Ecto

Resources

License

Stars

2 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages