{"id":15024866,"url":"https://github.com/josemrb/ecto_ltree","last_synced_at":"2025-04-12T12:31:58.964Z","repository":{"id":31406091,"uuid":"127781686","full_name":"josemrb/ecto_ltree","owner":"josemrb","description":"Ecto support for the PostgreSQL’s ltree data type","archived":false,"fork":false,"pushed_at":"2022-12-20T07:03:48.000Z","size":39,"stargazers_count":35,"open_issues_count":5,"forks_count":10,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-04-10T03:05:51.376Z","etag":null,"topics":["ecto","ecto-types","elixir","elixir-library","ltree","postgres","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josemrb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-02T16:22:25.000Z","updated_at":"2024-11-22T14:09:35.000Z","dependencies_parsed_at":"2023-01-14T18:58:42.533Z","dependency_job_id":null,"html_url":"https://github.com/josemrb/ecto_ltree","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josemrb%2Fecto_ltree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josemrb%2Fecto_ltree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josemrb%2Fecto_ltree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josemrb%2Fecto_ltree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josemrb","download_url":"https://codeload.github.com/josemrb/ecto_ltree/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248566568,"owners_count":21125688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecto","ecto-types","elixir","elixir-library","ltree","postgres","postgresql"],"created_at":"2024-09-24T20:01:05.662Z","updated_at":"2025-04-12T12:31:58.593Z","avatar_url":"https://github.com/josemrb.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EctoLtree\n[![Hex Version](https://img.shields.io/hexpm/v/ecto_ltree.svg?style=flat)](https://hex.pm/packages/ecto_ltree)\n\nA library that provides the necessary modules to support the PostgreSQL’s\n`ltree` data type with Ecto.\n\n## Quickstart\n\n### 1. Add the package to your list of dependencies in `mix.exs`\n\n#### If you are using Elixir \u003e= v1.7 and Ecto ~\u003e 3.2\n\n```elixir\ndef deps do\n  [\n    ...\n    {:ecto_ltree, \"~\u003e 0.3.0\"}\n  ]\nend\n```\n\n#### If you are using Ecto ~\u003e 3.0\n\n```elixir\ndef deps do\n  [\n    ...\n    {:ecto_ltree, \"~\u003e 0.2.0\"}\n  ]\nend\n```\n\n#### If you are using Elixir v1.6 and Ecto ~\u003e 2.1\n\n```elixir\ndef deps do\n  [\n    ...\n    {:ecto_ltree, \"~\u003e 0.1.0\"}\n  ]\nend\n\n```\n### 2. Define a type module with our custom extensions\n\n```elixir\nPostgrex.Types.define(\n  MyApp.PostgresTypes,\n  [EctoLtree.Postgrex.Lquery, EctoLtree.Postgrex.Ltree] ++ Ecto.Adapters.Postgres.extensions()\n)\n```\n\n### 3. Configure the Repo to use the previously defined type module\n\n```elixir\n  config :my_app, MyApp.Repo,\n    adapter: Ecto.Adapters.Postgres,\n    username: \"postgres\",\n    password: \"postgres\",\n    database: \"my_app_dev\",\n    hostname: \"localhost\",\n    poolsize: 10,\n    pool: Ecto.Adapters.SQL.Sandbox,\n    types: MyApp.PostgresTypes\n```\n\n### 4. Add a migration to enable the `ltree` extension\n\n```elixir\ndefmodule MyApp.Repo.Migrations.CreateExtensionLtree do\n  use Ecto.Migration\n\n  def change do\n    execute(\"CREATE EXTENSION ltree\",\n            \"DROP EXTENSION ltree\")\n  end\nend\n```\n\n### 5. Add a migration to create your table\n\n```elixir\ndefmodule MyApp.Repo.Migrations.CreateItems do\n  use Ecto.Migration\n\n  def change do\n    create table(:items) do\n      add :path, :ltree\n    end\n\n    create index(:items, [:path], using: :gist)\n  end\nend\n```\n\n### 6. Define an Ecto Schema\n\n```elixir\ndefmodule MyApp.Item do\n  use Ecto.Schema\n  import Ecto.Changeset\n  alias EctoLtree.LabelTree, as: Ltree\n\n  schema \"items\" do\n    field :path, Ltree\n  end\n\n  def changeset(item, params \\\\ %{}) do\n    item\n    |\u003e cast(params, [:path])\n  end\nend\n```\n\n### 7. Usage\n\n```elixir\niex(1)\u003e alias MyApp.Repo\nMyApp.Repo\niex(2)\u003e alias MyApp.Item\nMyApp.Item\niex(3)\u003e import Ecto.Query\nEcto.Query\niex(4)\u003e import EctoLtree.Functions\nEctoLtree.Functions\niex(5)\u003e Item.changeset(%Item{}, %{path: “1.2.3”}) |\u003e Repo.insert!\n%MyApp.Item{\n  __meta__: #Ecto.Schema.Metadata\u003c:loaded, “items”\u003e,\n  id: 1,\n  path: %EctoLtree.LabelTree{labels: [“1”, “2”, “3”]}\n}\niex(6)\u003e from(item in Item, select: nlevel(item.path)) |\u003e Repo.one\n3\n```\n\nThe documentation can be found at [hexdocs](https://hexdocs.pm/ecto_ltree).\n\n## Copyright and License\n\nCopyright (c) 2018-2019 Jose Miguel Rivero Bruno\n\nThe source code is licensed under [The MIT License (MIT)](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosemrb%2Fecto_ltree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosemrb%2Fecto_ltree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosemrb%2Fecto_ltree/lists"}