{"id":21314986,"url":"https://github.com/elbow-jason/dgraph_ex","last_synced_at":"2025-07-12T01:31:26.459Z","repository":{"id":57489846,"uuid":"98305632","full_name":"elbow-jason/dgraph_ex","owner":"elbow-jason","description":"A database wrapper and http client for dgraph","archived":false,"fork":false,"pushed_at":"2017-12-17T19:05:35.000Z","size":167,"stargazers_count":21,"open_issues_count":16,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-24T00:06:50.895Z","etag":null,"topics":["database-wrapper","dgraph","elixir"],"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/elbow-jason.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-25T12:50:30.000Z","updated_at":"2023-09-01T08:52:36.000Z","dependencies_parsed_at":"2022-08-29T19:31:19.513Z","dependency_job_id":null,"html_url":"https://github.com/elbow-jason/dgraph_ex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/elbow-jason/dgraph_ex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbow-jason%2Fdgraph_ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbow-jason%2Fdgraph_ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbow-jason%2Fdgraph_ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbow-jason%2Fdgraph_ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elbow-jason","download_url":"https://codeload.github.com/elbow-jason/dgraph_ex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbow-jason%2Fdgraph_ex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264923080,"owners_count":23683716,"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":["database-wrapper","dgraph","elixir"],"created_at":"2024-11-21T18:17:01.172Z","updated_at":"2025-07-12T01:31:26.026Z","avatar_url":"https://github.com/elbow-jason.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DgraphEx \n[![Build Status](https://travis-ci.org/elbow-jason/dgraph_ex.svg?branch=master)](https://travis-ci.org/elbow-jason/dgraph_ex) [![Hex Version][hex-img]][hex] [![License][license-img]][license]\n\n[hex-img]: https://img.shields.io/hexpm/v/dgraph_ex.svg\n[hex]: https://hex.pm/packages/dgraph_ex\n[license-img]: http://img.shields.io/badge/license-MIT-brightgreen.svg\n[license]: http://opensource.org/licenses/MIT\n\nAn elixir database wrapper for dgraph database.\n\nWorks with dgraph v0.8.1 (most current release as of 16 AUG 2017)\n\n[Docs](https://hexdocs.pm/dgraph_ex)\n\n##### Installation: \n\n```elixir\ndef deps do\n  [{:dgraph_ex, \"~\u003e 0.1.5\"}]\nend\n```\n\n\n## Usage \n\n#### define a model\n\n```elixir\n\ndefmodule Person do\n  use DgraphEx.Vertex\n\n  vertex :person do\n    field :name,    :string, index: [:exact, :term]\n    field :address, :string, index: [:exact, :term]\n  end\nend\n\n```\n\n```elixir\n\ndefmodule Land do\n  use Vertex\n\n  vertex :land do\n    field :address,             :string,  index: [:exact, :term],  count: true\n    field :zipcode,             :string,  index: [:exact],         count: true\n    field :city,                :string,  index: [:exact],         count: true\n    field :land_size,           :int,     index: true\n    field :living_space,        :int,     index: true\n    field :zoning,              :string,  index: [:exact],         count: true\n    field :floors,              :int\n    field :construction_year,   :string\n    field :geo_center,          :geo,     index: [:geo]\n    field :geo_border,          :geo,     index: [:geo]\n    field :owner,               :uid,     model: Person, reverse: true\n  end\nend\n\n```\n\n#### mutate the schema\n\n```elixir\nimport DgraphEx\nalias DgraphEx.Repo\n\n{:ok, _} = Repo.request mutation(schema: Land)\n{:ok, _} = Repo.request mutation(schema: Person)\n\n```\n\n#### define a changeset\n\n```elixir\n\n  alias DgraphEx.Changeset\n\n  def changeset(%Person{} = model, changes) when is_map(changes) do\n    model\n    |\u003e Changeset.cast(changes, _allowed_fields = [:name, :address])\n    |\u003e Changeset.validate_required(_required_fields = [:name, :address])\n    |\u003e Changeset.validate_type(_typed_fields = [:name, :address])\n    |\u003e Changeset.uncast\n  end\n\n```\n\n#### insert a model\n\nWe apply the `changeset` function to ensure data consistency:\n\n```elixir\n{:ok, person} =\n  %Person{} \n  |\u003e Person.changeset(%{name: \"jason\", address: \"221B Baker St. London, England 55555\"})\n```\n\nAnd `person` is:\n\n```elixir\n  %Person{\n    _uid_: nil,\n    address: \"221B Baker St. London, England 55555\",\n    name: \"jason\",\n  }\n```\n\nThen we insert into the `Repo`:\n\n```elixir\n{:ok, person} = Repo.insert(person)\n```\n\nThe resulting `person` is:\n\n(notice the `_uid_` is populated)\n\n```elixir\n%Person{\n  _uid_: \"0x11c\",\n  address: \"221B Baker St. London, England 55555\",\n  name: \"jason\",\n}\n```\n\n#### update a model\n\nUsing the `person` from above:\n\n```elixir\n{:ok, person} = Person.changeset(person, %{name: \"John Lakeman\"})\nperson = Repo.update(person)\n```\n\n#### get a model by `_uid_`.\n\n```elixir\nRepo.get(Company, \"0x11c\")\n```\nreturns `nil` or a populated `%Company{}` \n\n\n#### find anything\n\nWith function syntax:\n\n```elixir\n\nimport DgraphEx\n\nquery()\n|\u003e func(:spy, eq(:name, \"John Lakeman\"))\n|\u003e select({\n  :_uid_,\n  :address,\n  :name,\n})\n|\u003e Repo.request\n\n```\n\nAgain with keyword (kwargs) syntax:\n\n```elixir\nimport DgraphEx\nalias DgraphEx.Repo\n\nquery([\n  get: :spy,\n  func: eq(:name, \"John Lakeman\"),\n  select: {\n    :_uid_,\n    :address,\n    :name,\n  },\n]) |\u003e Repo.request\n\n```\n\nBoth of the above requests for \"spy\" result in the same response:\n\n```elixir\n{:ok, %{\n  \"spy\" =\u003e [\n    %{\n      \"_uid_\" =\u003e \"0x11c\",\n      \"address\" =\u003e \"221B Baker St. London, England 55555\",\n      \"name\" =\u003e \"John Lakeman\",\n    }\n  ]\n}}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felbow-jason%2Fdgraph_ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felbow-jason%2Fdgraph_ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felbow-jason%2Fdgraph_ex/lists"}