jerel / ecto_fields Goto Github PK
View Code? Open in Web Editor NEWProvides common fields for Ecto
License: MIT License
Provides common fields for Ecto
License: MIT License
For example:
EctoFields.URL.cast("http://example.com:1234/")
:error
Problem appears to be at https://github.com/jerel/ecto_fields/blob/master/lib/fields/url.ex#L60
Hi!
My schema:
defmodule Sandbox.Api.Request do
use Ecto.Schema
import Ecto.Changeset
schema "requests" do
field :useragent, :string
field :ip, EctoFields.IP
timestamps()
end
@doc false
def changeset(request, attrs) do
request
|> cast(attrs, [:useragent, :ip])
|> validate_required([:useragent, :ip])
end
end
Migration:
defmodule Sandbox.Repo.Migrations.CreateRequests do
use Ecto.Migration
def change do
create table(:requests) do
add :useragent, :text
add :ip, EctoFields.IP
timestamps()
end
end
end
But on mix ecto migrate
info] == Running Sandbox.Repo.Migrations.CreateRequests.change/0 forward
** (ArgumentError) EctoFields.IP is not a valid database type, please use an atom like :string, :text and so on
(ecto) lib/ecto/migration.ex:892: Ecto.Migration.validate_type!/1
(ecto) lib/ecto/migration.ex:687: Ecto.Migration.add/3
priv/repo/migrations/20180601072733_create_requests.exs:7: Sandbox.Repo.Migrations.CreateRequests.change/0
(stdlib) timer.erl:197: :timer.tc/3
(ecto) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/6
(ecto) lib/ecto/migrator.ex:128: Ecto.Migrator.attempt/6
(ecto) lib/ecto/migrator.ex:73: anonymous fn/4 in Ecto.Migrator.do_up/4
(ecto) lib/ecto/adapters/sql.ex:576: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
(db_connection) lib/db_connection.ex:1283: DBConnection.transaction_run/4
(db_connection) lib/db_connection.ex:1207: DBConnection.run_begin/3
(db_connection) lib/db_connection.ex:798: DBConnection.transaction/3
(ecto) lib/ecto/migrator.ex:261: anonymous fn/4 in Ecto.Migrator.migrate/4
(elixir) lib/enum.ex:1294: Enum."-map/2-lists^map/1-0-"/2
(ecto) lib/mix/tasks/ecto.migrate.ex:83: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
(elixir) lib/enum.ex:737: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:737: Enum.each/2
(mix) lib/mix/task.ex:314: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:80: Mix.CLI.run_task/2
Example:
defmodule EctoFields.URL do
# add `t:t/0`
@type t() :: String.t()
...
end
This is useful for your typespec struct definitions
The current release, 0.0.4, does not include the IPv4 field.
Currently I am unable to use this library with ecto@3
.
» mix deps.get
Running dependency resolution...
Failed to use "ecto" (version 3.0.7) because
ecto_fields (versions 1.1.0 to 1.1.5) requires ~> 2.0
ecto_sql (version 3.0.5) requires ~> 3.0.6
phoenix_ecto (version 4.0.0) requires ~> 3.0
mix.lock specifies 3.0.7
** (Mix) Hex dependency resolution failed, change the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}
Do you have any plans to release a new version?
Here are my deps:
defp deps do
[
{:phoenix, "~> 1.4.10"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 4.0"},
{:phoenix_live_view, "~> 0.9.0"},
{:ecto_sql, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:gettext, "~> 0.11"},
{:jason, "~> 1.1"},
{:plug_cowboy, "~> 2.1"},
# {:mix_test_watch, "~> 0.8", only: :dev},
{:nanoid, "~> 2.0.1"},
{:map_diff, "~> 1.3.2"},
{:poison, "~> 3.1.0"},
{:ueberauth_google, "~> 0.8"},
{:timex, "~> 3.6.1"},
{:merkle_tree, "~> 1.6.0"},
{:credo, "~> 1.0.0", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false},
{:paper_trail, "~> 0.8.1"},
{:csv, "~> 2.3"},
{:rollbax, ">= 0.0.0"},
{:hound, "~> 1.0", only: [:test]},
{:bamboo, "~> 1.3"},
{:premailex, "~> 0.3.10"},
{:earmark, "~> 1.3.2"},
{:inflex, "~> 2.0.0"},
{:recase, "~> 0.5"},
{:faker, "~> 0.13"},
{:ecto_fields, "~> 1.2.0"},
{:phoenix_html_simplified_helpers, "~> 2.1.0"},
{:mix_test_watch, "~> 1.0", only: :dev, runtime: false},
{:ex_unit_notifier, "~> 0.1", only: :test},
{:phoenix_slime, "~> 0.13.1"},
{:httpoison, "~> 1.6"},
{:shorter_maps, "~> 2.1.0"}
]
end
And the warnings shown during mix.deps.get
:
==> ecto_fields
Compiling 10 files (.ex)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.Atom)
lib/fields/atom.ex:1: EctoFields.Atom (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.Atom)
lib/fields/atom.ex:1: EctoFields.Atom (module)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.IP)
lib/fields/ip.ex:1: EctoFields.IP (module)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.IPv4)
lib/fields/ip4.ex:1: EctoFields.IPv4 (module)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.Email)
lib/fields/email.ex:1: EctoFields.Email (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.IP)
lib/fields/ip.ex:1: EctoFields.IP (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.Email)
lib/fields/email.ex:1: EctoFields.Email (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.IPv4)
lib/fields/ip4.ex:1: EctoFields.IPv4 (module)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.Slug)
lib/fields/slug.ex:1: EctoFields.Slug (module)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.PositiveInteger)
lib/fields/positive_integer.ex:1: EctoFields.PositiveInteger (module)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.IPv6)
lib/fields/ip6.ex:1: EctoFields.IPv6 (module)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module EctoFields.URL)
lib/fields/url.ex:1: EctoFields.URL (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.PositiveInteger)
lib/fields/positive_integer.ex:1: EctoFields.PositiveInteger (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.IPv6)
lib/fields/ip6.ex:1: EctoFields.IPv6 (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.Slug)
lib/fields/slug.ex:1: EctoFields.Slug (module)
warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module EctoFields.URL)
lib/fields/url.ex:1: EctoFields.URL (module)
Generated ecto_fields app
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.