thousandsofthem

thousandsofthem

At this moment postgrex package have built-in point data type (geometric, not a PostGIS one), according to the source code:
https://github.com/elixir-ecto/postgrex/blob/master/lib/postgrex/builtins.ex#L74
https://github.com/elixir-ecto/postgrex/blob/master/lib/postgrex/extensions/point.ex

I’m trying to use it with Ecto, no luck so far. Is there a way to use it in ecto schema? Regular way (Postgrex.Types.define) doesn’t seem to work for me

Showing Posts 1 to 4

thousandsofthem

thousandsofthem OP

UPD: created custom ecto wrapper, seems to be working correctly. No idea why no one did that before

defmodule App.EctoPoint do
  @behaviour Ecto.Type
  def type, do: Postgrex.Point

  # Casting from input into point struct
  def cast(value = %Postgrex.Point{}), do: {:ok, value}
  def cast(_), do: :error

  # loading data from the database
  def load(data) do
    {:ok, data}
  end

  # dumping data to the database
  def dump(value = %Postgrex.Point{}), do: {:ok, value}
  def dump(_), do: :error
end
josevalim

josevalim

Creator of Elixir

That looks great. Also see the geo_postgis library: GitHub - felt/geo_postgis: Postgrex Extension for PostGIS · GitHub :slight_smile:

thousandsofthem

thousandsofthem OP

Sure. Besides, geo_postgis is for PostGIS stuff (separate package, not installed by default), not a regular point .
e.g. PostGIS’ Geo.Point includes coordinates and srid projection, different data type.
PostGIS makes sense if someone goes full-blown geographic approach, for more humble use-cases (e.g. sort stuff by distance to a person, sped up by an index) point is more than enough

josevalim

josevalim

Creator of Elixir

I see. Thanks for clarifying!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews