{"id":13508806,"url":"https://github.com/sheharyarn/ecto_rut","last_synced_at":"2025-04-13T06:42:00.408Z","repository":{"id":57493641,"uuid":"69129000","full_name":"sheharyarn/ecto_rut","owner":"sheharyarn","description":"Ecto Model shortcuts to make your life easier! :tada:","archived":false,"fork":false,"pushed_at":"2018-08-16T10:55:56.000Z","size":79,"stargazers_count":113,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T11:53:39.409Z","etag":null,"topics":["ecto","elixir","hacktoberfest","phoenix-framework"],"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/sheharyarn.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}},"created_at":"2016-09-24T21:37:10.000Z","updated_at":"2025-01-17T03:18:49.000Z","dependencies_parsed_at":"2022-08-28T15:14:52.856Z","dependency_job_id":null,"html_url":"https://github.com/sheharyarn/ecto_rut","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fecto_rut","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fecto_rut/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fecto_rut/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fecto_rut/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sheharyarn","download_url":"https://codeload.github.com/sheharyarn/ecto_rut/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675440,"owners_count":21143763,"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","elixir","hacktoberfest","phoenix-framework"],"created_at":"2024-08-01T02:00:58.725Z","updated_at":"2025-04-13T06:42:00.385Z","avatar_url":"https://github.com/sheharyarn.png","language":"Elixir","funding_links":[],"categories":["ORM and Datamapping"],"sub_categories":[],"readme":"[\u003cimg src='media/logo.png' width='400px' /\u003e][docs]\n=====================\n\n[![Build Status][shield-travis]][travis-ci]\n[![Coverage Status][shield-inch]][inch-ci]\n[![Version][shield-version]][hexpm]\n[![License][shield-license]][hexpm]\n\u003c!--[![Downloads][shield-downloads]][hexpm] --\u003e\n\n\u003e Provides simple, sane and terse shortcuts for Ecto models.\n\nEcto.Rut is a wrapper around `Ecto.Repo` methods that usually require you to pass\nthe module as the subject and sometimes even require you do extra work before hand,\n(as in the case of `Repo.insert/3`) to perform operations on your database. Ecto.Rut\ntries to reduce code repetition by following the \"Convention over Configuration\"\nideology.\n\nSee the [Ecto.Rut Documentation][docs] on HexDocs.\n\n\n\n## Basic Usage\n\nYou can call normal `Ecto.Repo` methods directly on the Models:\n\n```elixir\nPost.all\n# instead of YourApp.Repo.all(Post)\n\nPost.get(2)\n# instead of YourApp.Repo.get(Post, 2)\n\nPost.insert(title: \"Awesome Post\", slug: \"awesome-post\", category_id: 3)\n# instead of:\n# changeset = Post.changeset(%Post{}, %{title: \"Awesome Post\", slug: \"awesome-post\", category_id: 3})\n# YourApp.Repo.insert(changeset)\n\n```\n\nSee the [Repo Coverage Section][github-coverage] or the [Hex Documentation][docs] for a full list of supported methods.\n\n\n\n## Installation\n\nAdd `:ecto_rut` as a dependency in your mix.exs file:\n\n```elixir\ndefp deps do\n  [{:ecto_rut, \"~\u003e 1.2.2\"}]\nend\n```\n\nand run:\n\n```bash\n$ mix deps.get\n```\n\n### Phoenix Projects\n\nIf you have an app built in [Phoenix Framework][phoenix], just add `use Ecto.Rut`\nin the `models` method in `web/web.ex` or anywhere else you have defined your\nbasic Schema structure:\n\n```elixir\n# web/web.ex\n\ndef model do\n  quote do\n    use Ecto.Schema\n    use Ecto.Rut, repo: YourApp.Repo\n\n    # Other stuff...\n  end\nend\n```\n\nThat's it! `Ecto.Rut` will automatically be loaded in all of your models. If you don't\nhave a central macro defined for your Schema, take a look at this example:\n[**Repo.Schema**][repo-schema-eg].\n\n### Other Ecto Projects\n\nIf you're not using Phoenix or you don't want to use Ecto.Rut with all of your models (why wouldn't\nyou!?), you'll have to manually add `use Ecto.Rut`:\n\n```elixir\ndefmodule YourApp.Post do\n  use Ecto.Schema\n  use Ecto.Rut, repo: YourApp.Repo\n\n  # Schema, Changeset and other stuff...\nend\n```\n\n\n\n## Configuration\n\nYou do not need to configure Ecto.Rut unless your app is set up differently. All values are\ninferred automatically and it should just work, but if you absolutely have to, you can specify\nthe `repo` and `model` modules:\n\n```elixir\ndefmodule YourApp.Post do\n  use Ecto.Schema\n  use Ecto.Rut, model: YourApp.Other.Post, repo: YourApp.Repo\nend\n```\n\nSee the [Configuration Section][docs-config] in HexDocs for more details.\n\n\n\n## Not for Complex Queries\n\n`Ecto.Rut` has been designed for simple use cases. It's not meant for advanced queries and\noperations on your Database. Ecto.Rut is supposed to do only simple tasks such as getting,\nupdating or deleting records. For any complex queries, you should use the original `Ecto.Repo`\nmethods.\n\nYou shouldn't also let Ecto.Rut handicap you; Ideally, you should understand how Ecto.Repo\nlets you do advanced queries and how Ecto.Rut places some limits on you (for example, not\nbeing able to specify custom options). José has also [shown his concern][jose-concern]:\n\n\u003e My concern with using something such as shortcuts is that people will forget those\n\u003e basic tenets schemas and repositories were built on.\n\nThat being said, Ecto.Rut's goal is to save time (and keystrokes) by following the convention\nover configuration ideology. You shouldn't need to call `YourApp.Repo` for every little task,\nor involve yourself with changesets everytime when you've already defined them in your model.\n\n\n\n## Methods\n\n### [All][fun-all]\n\n```elixir\niex\u003e Post.all\n[%Post{id: 1, title: \"Post 1\"},\n %Post{id: 2, title: \"Post 2\"},\n %Post{id: 3, title: \"Post 3\"}]\n```\n\n\n### [Get][fun-get]\n\n```elixir\niex\u003e Post.get(2).title\n\"Blog Post No. 2\"\n```\n\nAlso see [`get!/1`][fun-get!]\n\n\n### [Get By][fun-get_by]\n\n```elixir\nPost.get_by(published_date: \"2014-10-22\")\n```\n\nAlso see [`get_by!/1`][fun-get_by!]\n\n\n### [Insert][fun-insert]\n\nYou can insert Changesets, Structs, Keyword Lists or Maps. When Structs, Keyword Lists or\nMaps are given, they'll be first converted into a changeset (as defined by your model) and\nvalidated before inserting.\n\nSo you don't need to create a changeset every time before inserting a new record.\n\n```elixir\n# Accepts Keyword Lists\nPost.insert(title: \"Introduction to Elixir\")\n\n# Accepts Maps\nPost.insert(%{title: \"Building your first Phoenix app\"})\n\n# Even accepts Structs (these would also be validated by your defined changeset)\nPost.insert(%Post{title: \"Concurrency in Elixir\", categories: [\"programming\", \"elixir\"]})\n```\n\nAlso see [`insert!/1`][fun-insert!]\n\n\n### [Update][fun-update]\n\nThere are two variations of the update method; [`update/1`][fun-update] and\n[`update/2`][fun-update2]. For the first, you can either pass a changeset (which would be\ninserted immediately) or a modified struct (which would first be converted into a changeset\nby comparing it with the existing record):\n\n```elixir\npost = Post.get(2)\nmodified_post = %{ post | title: \"New Post Title\" }\nPost.update(modified_post)\n```\n\nThe second method is to pass the original record as the subject and a Keyword List (or a Map)\nof the new attributes. This method is recommended:\n\n```elixir\npost = Post.get(2)\nPost.update(post, title: \"New Post Title\")\n```\n\nAlso see [`update!/1`][fun-update!] and [`update!/2`][fun-update2!]\n\n\n### [Delete][fun-delete]\n\n```elixir\npost = Post.get_by(id: 9)\nPost.delete(post)\n```\n\nAlso see [`delete!/1`][fun-delete!]\n\n\n### [Delete All][fun-delete_all]\n\n```elixir\nPost.delete_all\n```\n\n\n\n## Method Coverage\n\n| Ecto.Repo Methods      | Ecto.Rut Methods  | Additional Notes                                     |\n|:-----------------------|:------------------|:-----------------------------------------------------|\n| Repo.aggregate         | —                 | —                                                    |\n| Repo.all               | Model.all         | —                                                    |\n| Repo.config            | —                 | —                                                    |\n| Repo.delete            | Model.delete      | —                                                    |\n| Repo.delete!           | Model.delete!     | —                                                    |\n| Repo.delete_all        | Model.delete_all  | —                                                    |\n| Repo.get               | Model.get         | —                                                    |\n| Repo.get!              | Model.get!        | —                                                    |\n| Repo.get_by            | Model.get_by      | —                                                    |\n| Repo.get_by!           | Model.get_by!     | —                                                    |\n| Repo.in_transaction?   | —                 | —                                                    |\n| Repo.insert            | Model.insert      | Accepts structs, changesets, keyword lists and maps  |\n| Repo.insert!           | Model.insert!     | Accepts structs, changesets, keyword lists and maps  |\n| Repo.insert_all        | —                 | —                                                    |\n| Repo.insert_or_update  | —                 | —                                                    |\n| Repo.insert_or_update! | —                 | —                                                    |\n| Repo.one               | —                 | —                                                    |\n| Repo.one!              | —                 | —                                                    |\n| Repo.preload           | —                 | —                                                    |\n| Repo.query             | —                 | —                                                    |\n| Repo.query!            | —                 | —                                                    |\n| Repo.rollback          | —                 | —                                                    |\n| Repo.start_link        | —                 | —                                                    |\n| Repo.stop              | —                 | —                                                    |\n| Repo.transaction       | —                 | —                                                    |\n| Repo.update            | Model.update      | Accepts structs, changesets, keyword lists and maps  |\n| Repo.update!           | Model.update!     | Accepts structs, changesets, keyword lists and maps  |\n| Repo.update_all        | —                 | —                                                    |\n\n\n\n## Roadmap\n\n - [x] Write Tests\n - [x] Write Documentation\n - [ ] Cover all main `Ecto.Repo` methods\n - [x] Allow explicitly passing Application and Repo modules to the `use Ecto.Rut` statement\n - [ ] Add support for preloading with existing methods\n - [ ] Introduce new wrapper and helper methods that do not exist in Ecto, such as:\n    - [ ] `Model.count`\n    - [ ] `Model.first` and `Model.last`\n    - [ ] `Model.find_or_create(obj)`\n    - [ ] Methods that accept direct arguments (E.g. `delete_by_id(3)`)\n\n\n\n## Contributing\n\n - [Fork][github-fork], Enhance, Send PR\n - Lock issues with any bugs or feature requests\n - Implement something from Roadmap\n - Spread the word\n\n\n\n## License\n\nThis package is available as open source under the terms of the [MIT License][license].\n\n\n\n  [logo]:             media/logo.png\n  [shield-version]:   https://img.shields.io/hexpm/v/ecto_rut.svg\n  [shield-license]:   https://img.shields.io/hexpm/l/ecto_rut.svg\n  [shield-downloads]: https://img.shields.io/hexpm/dt/ecto_rut.svg\n  [shield-travis]:    https://img.shields.io/travis/sheharyarn/ecto_rut/master.svg\n  [shield-inch]:      http://inch-ci.org/github/sheharyarn/ecto_rut.svg?branch=master\n\n  [license]:          http://opensource.org/licenses/MIT\n  [phoenix]:          https://github.com/phoenixframework/phoenix\n  [travis-ci]:        https://travis-ci.org/sheharyarn/ecto_rut\n  [inch-ci]:          http://inch-ci.org/github/sheharyarn/ecto_rut\n  [jose-concern]:     https://elixirforum.com/t/need-code-review/1770/5?u=sheharyarn\n\n  [github-coverage]:  https://github.com/sheharyarn/ecto_rut#method-coverage\n  [github-fork]:      https://github.com/sheharyarn/ecto_rut/fork\n  [repo-schema-eg]:   https://github.com/sheharyarn/ztd/blob/master/lib/ztd/repo/schema.ex\n\n  [hexpm]:            https://hex.pm/packages/ecto_rut\n  [docs]:             https://hexdocs.pm/ecto_rut/Ecto.Rut.html\n  [docs-config]:      https://hexdocs.pm/ecto_rut/Ecto.Rut.html#module-configuration\n\n  [fun-all]:          https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:all/0\n  [fun-delete]:       https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:delete/1\n  [fun-delete!]:      https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:delete!/1\n  [fun-delete_all]:   https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:delete_all/0\n  [fun-get]:          https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:get/1\n  [fun-get!]:         https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:get!/1\n  [fun-get_by]:       https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:get_by/1\n  [fun-get_by!]:      https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:get_by!/1\n  [fun-insert]:       https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:insert/1\n  [fun-insert!]:      https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:insert!/1\n  [fun-update]:       https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:update/1\n  [fun-update2]:      https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:update/2\n  [fun-update!]:      https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:update!/1\n  [fun-update2!]:     https://hexdocs.pm/ecto_rut/Ecto.Rut.html#c:update!/2\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheharyarn%2Fecto_rut","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsheharyarn%2Fecto_rut","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheharyarn%2Fecto_rut/lists"}