-
Notifications
You must be signed in to change notification settings - Fork 48
introduce Ecto.Adapters.SQLite3.Extension #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce Ecto.Adapters.SQLite3.Extension #167
Conversation
this allows type extensions to be registered at runtime via the `:ecto_sqlite3, extensions:` configuration key, which takes a list of modules that implement the `Extension` behaviour.
It would have been nice to have this configurable on a per-Repo basis, but I was unable to find a (non-hacky) way to get at the repo configuration in the |
Update: I now have a working SpatialLite implementation using this PR :) |
On further investigation, this is not quite enough ... it works very nicely with Ecto, but any structs that are directly added to a query end up being passed directly to the |
|
…tabase (#333) Introduces a runtime extension to convert data types into something that can be serialized into the database. See elixir-sqlite/ecto_sqlite3#167 and elixir-sqlite/ecto_sqlite3#166 My primary goal is to be able to use Spatialite from Elixir. With this PR and the one against `ecto_sqlite3`, it is 95% of the way there. With these two PRs applied, one can now do things like: ```elixir defmodule Location do use Ecto.Schema schema "locations" do field(:name, :string) field(:geom, GeoSQL.Geometry) end end MyApp.Repo.all(from(location in Location, select: MM2.distance(location.geom, ^geometry))) ``` .. and it just works, regardless of whether `MyApp.Repo` is point at a PostgreSQL database with PostGIS enabled, or an SQLite3 database with Spatialite loaded. The one remaining annoyance is getting structs back *out* of the database without going through ecto (which *does* work with the `ecto_sqlite3` PR!). So, I still have to figure out a nice way for the user to get back `Geo` structs from raw queries such as: ``` from(location in Location, limit: 1, select: MM2.transform(location.geom, 3452)) ``` But otherwise everything Just Works transparently with this change.
Small update: the If/when this PR is merged, I will publish that library on |
If you'd like to play around with the Spatialite bits, the repository is here: https://github.com/expothecary/geo_sql I finally got all the tests working this evening, which I wanted to get done before sharing it around. It needs more unit tests, but they will come. It's pretty neat to be able to use the same code for both PostGIS and Spatialite, so long as one sticks to the MM2, MM3, and Common functions. But it works rather decently, all things considered. |
This allows type extensions to be registered at runtime via the
:ecto_sqlite3, extensions:
configuration key, which takes a list of modules that implement theExtension
behaviour.See #166
This allows for an extension as simple as this to support storing and retrieving all the types in the
geo
library:On a related note: this is still not sufficient to use with the SQL/MM GIS functions (the
ST_*
ones in SpatialLite), as while storing WKB works fine, Spatialite has it's own almost-but-not-quite-standard-wkb storage format (a truly daft idea) and has a few other minor incompatibilities such as seemingly not supportingSRID:<number>
values in WKT/WKB ... so there's still some work to do to leverage this into full, proper Spatialite support ... but I'm working on that as a separate issue in another repo.This is sufficient for serialization/deserialization of custom data types, however.