Skip to content

jorgevilaca82/hydrex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hydrex

Hydrex allows you to automattically fill up all virtual fields or your Ecto model at once.

In order to use it you need to define a virtual field in your Ecto model and a resolver function for that virtual field with the same name and finally you derive your model with Hydratable protocol.

defmodule MyApp.Url do
  #...
  @derive {Hydrex.Hydratable, []}
  schema "urls" do
    field :link, :string
    field :title, :string

    # Virtual field
    field :is_safe, :boolean, virtual: true
  end

  # resolver function
  def is_safe(url) do
    String.starts_with?(url.link, "https://")
  end
end

And when calling you can pass an opts list informing whether or not you want your ecto models hydrated.

import Hydrex.Hydratable.Utils, only: [maybe_hydrate: 2]

Repo.all(Url) |> maybe_hydrate(hydrate: true)

Installation

If available in Hex, the package can be installed by adding hydrex to your list of dependencies in mix.exs:

def deps do
  [
    {:hydrex, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/hydrex.

About

Fills up all Ecto model virtual fields at once

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages