Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshdholtz/ecto-lazy-float
Ecto.LazyFloat - An Ecto.Float that accepts binary and integers
https://github.com/joshdholtz/ecto-lazy-float
Last synced: about 2 months ago
JSON representation
Ecto.LazyFloat - An Ecto.Float that accepts binary and integers
- Host: GitHub
- URL: https://github.com/joshdholtz/ecto-lazy-float
- Owner: joshdholtz
- License: mit
- Created: 2015-02-15T20:36:15.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-15T20:07:48.000Z (almost 7 years ago)
- Last Synced: 2024-10-11T10:32:26.175Z (2 months ago)
- Language: Elixir
- Homepage:
- Size: 164 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Ecto.LazyFloat - An Ecto.Float that accepts binary and integers. (ORM and Datamapping)
- fucking-awesome-elixir - ecto_lazy_float - Ecto.LazyFloat - An Ecto.Float that accepts binary and integers. (ORM and Datamapping)
- awesome-elixir - ecto_lazy_float - Ecto.LazyFloat - An Ecto.Float that accepts binary and integers. (ORM and Datamapping)
README
# Ecto.LazyFloat
Ecto.LazyFloat - An Ecto.Float that accepts binary and integersFind on Hex - https://hex.pm/packages/ecto_lazy_float
## Installation
Add Ecto.LazyFloat as a dependency in your `mix.exs` file.```elixir
defp deps do
[{:postgrex, ">= 0.0.0"},
{:ecto, "~> 0.7"},
{:ecto_lazy_float, "~> 0.1.2"}]
end
```After you are done, run `mix deps.get` in your shell to fetch the dependencies.
## Usage
Enable LazyFloat through an Ecto model schema:
```elixir
defmodule YourProject.Thing do
use Ecto.Modelschema "things" do
field :notes, :string
field :position, :integer
field :value, Ecto.LazyFloat
end
end
``````elixir
# With integer
valid = Ecto.Changeset.cast(%{value: 1}, %Thing{}, [], [])
Repo.insert(valid)# With string
valid = Ecto.Changeset.cast(%{value: "1.2"}, %Thing{}, [], [])
Repo.insert(valid)# With float
valid = Ecto.Changeset.cast(%{value: 1.2}, %Thing{}, [], [])
Repo.insert(valid)
```