{"id":13508751,"url":"https://github.com/stavro/arc_ecto","last_synced_at":"2025-05-15T17:03:09.311Z","repository":{"id":33912914,"uuid":"37630974","full_name":"stavro/arc_ecto","owner":"stavro","description":"An integration with Arc and Ecto.","archived":false,"fork":false,"pushed_at":"2023-09-21T16:03:51.000Z","size":78,"stargazers_count":254,"open_issues_count":39,"forks_count":151,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-07T21:15:43.157Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"gitchain/gitchain","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stavro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-06-18T01:41:50.000Z","updated_at":"2024-12-28T16:34:49.000Z","dependencies_parsed_at":"2024-01-08T19:22:14.655Z","dependency_job_id":null,"html_url":"https://github.com/stavro/arc_ecto","commit_stats":{"total_commits":77,"total_committers":30,"mean_commits":2.566666666666667,"dds":"0.48051948051948057","last_synced_commit":"ca32aa5dc4d3a60bbbd82efa089b17d5a4e098e6"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stavro%2Farc_ecto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stavro%2Farc_ecto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stavro%2Farc_ecto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stavro%2Farc_ecto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stavro","download_url":"https://codeload.github.com/stavro/arc_ecto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384937,"owners_count":22062421,"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":[],"created_at":"2024-08-01T02:00:57.929Z","updated_at":"2025-05-15T17:03:09.284Z","avatar_url":"https://github.com/stavro.png","language":"Elixir","funding_links":[],"categories":["ORM and Datamapping"],"sub_categories":[],"readme":"Arc.Ecto\n========\n\nArc.Ecto provides an integration with [Arc](https://github.com/stavro/arc) and Ecto.\n\nInstallation\n============\n\nAdd the latest stable release to your `mix.exs` file:\n\n```elixir\ndefp deps do\n  [\n    {:arc_ecto, \"~\u003e 0.11.3\"}\n  ]\nend\n```\n\nThen run `mix deps.get` in your shell to fetch the dependencies.\n\nUsage\n=====\n\n### Add Arc.Ecto.Definition\n\nAdd a second using macro `use Arc.Ecto.Definition` to the top of your Arc definitions.\n\n```elixir\ndefmodule MyApp.Avatar do\n  use Arc.Definition\n  use Arc.Ecto.Definition\n\n  # ...\nend\n```\n\nThis provides a set of functions to ease integration with Arc and Ecto.  In particular:\n\n  * Definition of a custom Ecto Type responsible for storing the images.\n  * Url generation with a cache-busting timestamp query parameter\n\n### Add a string column to your schema\n\nArc attachments should be stored in a string column, with a name indicative of the attachment.\n\n```elixir\ncreate table :users do\n  add :avatar, :string\nend\n```\n\n### Add your attachment to your Ecto Schema\n\nAdd a using statement `use Arc.Ecto.Schema` to the top of your ecto schema, and specify the type of the column in your schema as `MyApp.Avatar.Type`.\n\nAttachments can subsequently be passed to Arc's storage though a Changeset `cast_attachments/3` function, following the syntax of `cast/3`\n\n```elixir\ndefmodule MyApp.User do\n  use MyApp.Web, :model\n  use Arc.Ecto.Schema\n\n  schema \"users\" do\n    field :name,   :string\n    field :avatar, MyApp.Avatar.Type\n  end\n\n  @doc \"\"\"\n  Creates a changeset based on the `data` and `params`.\n\n  If no params are provided, an invalid changeset is returned\n  with no validation performed.\n  \"\"\"\n  def changeset(user, params \\\\ :invalid) do\n    user\n    |\u003e cast(params, [:name])\n    |\u003e cast_attachments(params, [:avatar])\n    |\u003e validate_required([:name, :avatar])\n  end\nend\n```\n\n### Save your attachments as normal through your controller\n\n```elixir\n  @doc \"\"\"\n  Given params of:\n\n  %{\n    \"id\" =\u003e 1,\n    \"user\" =\u003e %{\n      \"avatar\" =\u003e %Plug.Upload{\n                    content_type: \"image/png\",\n                    filename: \"selfie.png\",\n                    path: \"/var/folders/q0/dg42x390000gp/T//plug-1434/multipart-765369-5\"}\n    }\n  }\n\n  \"\"\"\n  def update(conn, %{\"id\" =\u003e id, \"user\" =\u003e user_params}) do\n    user = Repo.get(User, id)\n    changeset = User.changeset(user, user_params)\n\n    if changeset.valid? do\n      Repo.update(changeset)\n\n      conn\n      |\u003e put_flash(:info, \"User updated successfully.\")\n      |\u003e redirect(to: user_path(conn, :index))\n    else\n      render conn, \"edit.html\", user: user, changeset: changeset\n    end\n  end\n```\n\n### Retrieve the serialized url\n\nBoth public and signed urls will include the timestamp for cache busting, and are retrieved the exact same way as using Arc directly.\n\n```elixir\n  user = Repo.get(User, 1)\n\n  # To receive a single rendition:\n  MyApp.Avatar.url({user.avatar, user}, :thumb)\n    #=\u003e \"https://bucket.s3.amazonaws.com/uploads/avatars/1/thumb.png?v=63601457477\"\n\n  # To receive all renditions:\n  MyApp.Avatar.urls({user.avatar, user})\n    #=\u003e %{original: \"https://.../original.png?v=1234\", thumb: \"https://.../thumb.png?v=1234\"}\n\n  # To receive a signed url:\n  MyApp.Avatar.url({user.avatar, user}, signed: true)\n  MyApp.Avatar.url({user.avatar, user}, :thumb, signed: true)\n```\n\n## License\n\nCopyright 2015 Sean Stavropoulos\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n      http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstavro%2Farc_ecto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstavro%2Farc_ecto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstavro%2Farc_ecto/lists"}