{"id":13500365,"url":"https://github.com/fazibear/defql","last_synced_at":"2025-08-20T03:31:46.610Z","repository":{"id":57489001,"uuid":"79348464","full_name":"fazibear/defql","owner":"fazibear","description":"Create elixir functions with SQL as a body.","archived":false,"fork":false,"pushed_at":"2018-08-11T14:26:53.000Z","size":52,"stargazers_count":103,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-23T22:11:52.211Z","etag":null,"topics":["database","ecto","elixir","sql"],"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/fazibear.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-01-18T14:36:05.000Z","updated_at":"2024-02-13T10:34:45.000Z","dependencies_parsed_at":"2022-08-29T10:30:22.952Z","dependency_job_id":null,"html_url":"https://github.com/fazibear/defql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fazibear%2Fdefql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fazibear%2Fdefql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fazibear%2Fdefql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fazibear%2Fdefql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fazibear","download_url":"https://codeload.github.com/fazibear/defql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230388131,"owners_count":18217755,"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","ecto","elixir","sql"],"created_at":"2024-07-31T22:00:57.552Z","updated_at":"2024-12-19T06:10:00.118Z","avatar_url":"https://github.com/fazibear.png","language":"Elixir","readme":"# Defql [![Package Version](https://img.shields.io/hexpm/v/defql.svg)](https://hex.pm/packages/defql) [![Code Climate](https://codeclimate.com/github/fazibear/defql/badges/gpa.svg)](https://codeclimate.com/github/fazibear/defql) [![Build Status](https://travis-ci.org/fazibear/defql.svg?branch=master)](https://travis-ci.org/fazibear/defql)\n\nCreate elixir functions with SQL as a body.\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `defql` to your list of dependencies in `mix.exs`:\n\n```elixir\ndefp deps do\n  [\n    {:defql, \"~\u003e 0.1.1\"},\n    {:postgrex, \"\u003e= 0.13.0\"}, # optional\n  ]\nend\n```\n\n\n### Configuration\n\nIt requires `adapter` key, and adapter specific options.\n\nUse with ecto:\n\n```elixir\nconfig :defql, connection: [\n  adapter: Defql.Adapter.Ecto.Postgres,\n  repo: YourApp.Repo\n]\n```\n\nUse standalone connection:\n\n```elixir\nconfig :defql, connection: [\n  adapter: Defql.Adapter.Postgres,\n  hostname: \"localhost\",\n  username: \"username\",\n  password: \"password\",\n  database: \"my_db\",\n  pool: DBConnection.Poolboy,\n  pool_size: 1\n]\n```\n\n## Usage\n\nWe can define module to have access to our database:\n\n```elixir\ndefmodule UserQuery do\n  use Defql\n\n  defselect get(conds), table: :users, columns: [:name, :email]\n  definsert add(params), table: :users\n  defupdate update(params, conds), table: :users\n  defdelete delete(conds), table: :users\n\n  defquery get_by_name(name, limit) do\n    \"SELECT * FROM users WHERE name = $name LIMIT $limit\"\n  end\nend\n```\n\nRight now we have easy access to `users` in database:\n\n```elixir\nUserQuery.get(id: \"3\") # =\u003e {:ok, [%{...}]}\nUserQuery.add(name: \"Smbdy\") # =\u003e {:ok, [%{...}]}\nUserQuery.update([name: \"Other\"],[id: \"2\"]) # =\u003e {:ok, [%{...}]}\nUserQuery.delete(id: \"2\") # =\u003e {:ok, [%{...}]}\n\nUserQuery.get_by_name(\"Ela\", 4) # =\u003e {:ok, [%{...}, %{...}]}\n```\n\nWe can also define common table for the whole module.\n\n```elixir\ndefmodule UserQuery do\n  use Defql, table: :users\n\n  defselect get(conds), columns: [:name, :email]\n  definsert add(params)\n  defupdate update(params, conds)\n  defdelete delete(conds)\nend\n```\n\n`%{...}` It's a hash with user properties straight from database.\n\nSupported condition statements:\n- `user_id: [1,2,3,4]`\n- `user_id: {:in, [1,2,3,4,5]}`\n- `name: {:like, \"%john%\"}`\n- `name: {:ilike, \"%john\"}`\n\n## TODO\n\n- [ ] MySQL support\n- [ ] Cleanup ECTO adapter\n- [ ] Support database errors\n- [ ] Transactions\n\n## Thank you!\n\n[![Become Patreon](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/bePatron?u=6912974)\n","funding_links":["https://www.patreon.com/bePatron?u=6912974"],"categories":["Elixir","ORM and Datamapping"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffazibear%2Fdefql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffazibear%2Fdefql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffazibear%2Fdefql/lists"}