{"id":18886759,"url":"https://github.com/supabase-community/postgrest-ex","last_synced_at":"2025-04-14T22:24:01.545Z","repository":{"id":219417310,"uuid":"748997837","full_name":"supabase-community/postgrest-ex","owner":"supabase-community","description":"Isomorphic Elixir client for PostgREST","archived":false,"fork":false,"pushed_at":"2025-01-15T23:52:37.000Z","size":3878,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T20:16:44.513Z","etag":null,"topics":[],"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/supabase-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-27T09:28:09.000Z","updated_at":"2025-04-04T04:42:26.000Z","dependencies_parsed_at":"2024-10-30T22:52:01.629Z","dependency_job_id":"65e6586e-b41a-484a-b655-3d67395e3523","html_url":"https://github.com/supabase-community/postgrest-ex","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"e1e2d747b8f38291e1916f4fa2f531a753053df9"},"previous_names":["zoedsoupe/postgrest-ex","supabase-community/postgrestex","supabase-community/postgrest-ex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase-community%2Fpostgrest-ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supabase-community","download_url":"https://codeload.github.com/supabase-community/postgrest-ex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248969839,"owners_count":21191335,"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":["elixir","hacktoberfest","hacktoberfest2021"],"created_at":"2024-11-08T07:30:35.655Z","updated_at":"2025-04-14T22:24:01.532Z","avatar_url":"https://github.com/supabase-community.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Supabase PostgREST\n\n[PostgREST](https://supabase.com/docs/guides/database/overview) implementation for the [Supabase Potion](https://hexdocs.pm/supabase_potion) SDK in Elixir.\n\nThe `Supabase.PostgREST` module provides a suite of functions to interact with a Supabase PostgREST API using a fluent interface. This allows you to construct and execute complex queries in the context of a Supabase database application, facilitating a more functional approach to managing database operations in Elixir.\n\nPlease, refers to the [official Supabase PostgREST](https://supabase.com/docs/guides/api) documentation to have the context on how to apply query and filters on your data, and also configure your project to expose the PostgREST API.\n\n## Installation\n\nAdd the following dependencies to your `mix.exs` file:\n\n```elixir\ndef deps do\n  [\n    {:supabase_potion, \"~\u003e 0.6\"},\n    {:supabase_postgrest, \"~\u003e 1.0\"}\n  ]\nend\n```\n\nThen, run `mix deps.get` to fetch the dependencies.\n\n## Usage\n\n### Initializing the Client\n\nBefore using the `Supabase.PostgREST` module, you need to initialize a Supabase client. This client handles the authentication and configuration needed to interact with the Supabase services.\n\nYou can initialize the client as can be found on the [Supabase Potion documentation](https://hexdocs.pm/supabase_potion/readme.html#usage)\n\nThis client struct is passed to the various `Supabase.PostgREST` functions to perform operations on your Supabase database.\n\n### Basic Operations\n\nHere’s how you can perform common operations using the `Supabase.PostgREST` module.\n\nNote that all operations and filters on `Supabase.PostgREST` are **lazy**, that means that queries, insertions, deletions and updates are only executed when you explicit call `Supabase.PostgREST.execute/1`.\n\n#### Selecting Data\n\nTo select records from a table, use the `from/2` and `select/3` functions:\n\n```elixir\niex\u003e alias Supabase.PostgREST, as: Q\niex\u003e Q.from(client, \"users\") |\u003e Q.select(\"*\", returning: true) |\u003e Q.execute()\niex\u003e {:ok, result} | {:error, %Supabase.PostgREST.Error{}}\n```\n\nYou can specify the columns to retrieve instead of using `*`:\n\n```elixir\niex\u003e Q.select(query, [\"id\", \"name\"], returning: true)\n```\n\n#### Inserting Data\n\nTo insert new records, use the `insert/3` function:\n\n```elixir\niex\u003e alias Supabase.PostgREST, as: Q\niex\u003e Q.from(client, \"users\") |\u003e Q.insert(%{name: \"John Doe\", age: 30}, returning: :representation) |\u003e Q.execute()\niex\u003e {:ok, result} | {:error, %Supabase.PostgREST.Error{}}\n```\n\n#### Updating Data\n\nTo update existing records, use the `update/3` function:\n\n```elixir\niex\u003e alias Supabase.PostgREST, as: Q\niex\u003e Q.from(client, \"users\") |\u003e Q.eq(\"id\", 1) |\u003e Q.update(%{name: \"John Smith\"}, returning: :representation) |\u003e Q.execute()\niex\u003e {:ok, result} | {:error, %Supabase.PostgREST.Error{}}\n```\n\n#### Deleting Data\n\nTo delete records, use the `delete/2` function:\n\n```elixir\niex\u003e alias Supabase.PostgREST, as: Q\niex\u003e Q.from(client, \"users\") |\u003e Q.eq(\"id\", 1) |\u003e Q.delete(query, returning: :representation) |\u003e Q.execute()\niex\u003e {:ok, result} | {:error, %Supabase.PostgREST.Error{}}\n```\n\n### Filtering Data\n\nYou can apply various filters to your queries using functions like `eq/3`, `lt/3`, `gt/3`, etc.\n\n```elixir\niex\u003e alias Supabase.PostgREST, as: Q\niex\u003e Q.from(client, \"users\") |\u003e Q.eq(\"status\", \"active\") |\u003e Q.select(\"*\", returning: true) |\u003e Q.execute()\niex\u003e {:ok, result} | {:error, %Supabase.PostgREST.Error{}}\n```\n\n### Advanced Query Building\n\nYou can also perform more advanced operations like full-text search, ordering, limiting, and combining filters using logical operators:\n\n```elixir\niex\u003e alias Supabase.PostgREST, as: Q\niex\u003e Q.from(client, \"users\")\n     |\u003e Q.text_search(\"name\", \"John\", type: :plain)\n     |\u003e Q.order(\"created_at\", asc: true)\n     |\u003e Q.select([\"id\", \"name\", \"created_at\"], returning: true)\n     |\u003e Q.execute()\niex\u003e {:ok, result} | {:error, %Supabase.PostgREST.Error{}}\n```\n\n### Executing Queries\n\nAfter constructing a query, you can execute it using the `execute/1` or `execute_to/2` functions. The `execute_to/2` function allows you to map the results directly to a specific schema:\n\n```elixir\niex\u003e defmodule User, do: defstruct([:id])\niex\u003e alias Supabase.PostgREST, as: Q\niex\u003e Q.from(client, \"users\")\n     |\u003e Q.eq(\"id\", 1)\n     |\u003e Q.select([\"id\"], returning: true)\n     |\u003e Q.execute_to(User)\niex\u003e {:ok, %User{} = user} | {:error, %Supabase.PostgREST.Error{}}\n```\n\n## Contributing\n\nIf you find any issues or have suggestions for improvements, please feel free to open an issue or a pull request on the GitHub repository.\n\n## License\n\nThis project is licensed under the MIT License.\n\n---\n\nThis README provides a clear and structured guide for users of your package, with accurate examples and explanations of how to use the various functions provided by the `Supabase.PostgREST` module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase-community%2Fpostgrest-ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupabase-community%2Fpostgrest-ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase-community%2Fpostgrest-ex/lists"}