{"id":13801015,"url":"https://github.com/artemeff/eql","last_synced_at":"2025-04-05T04:14:38.426Z","repository":{"id":25539241,"uuid":"28971895","full_name":"artemeff/eql","owner":"artemeff","description":"Erlang with SQL or not","archived":false,"fork":false,"pushed_at":"2024-01-02T21:03:39.000Z","size":32,"stargazers_count":116,"open_issues_count":3,"forks_count":18,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-29T03:11:14.363Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Erlang","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/artemeff.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}},"created_at":"2015-01-08T15:25:44.000Z","updated_at":"2024-12-20T07:48:21.000Z","dependencies_parsed_at":"2024-01-08T20:19:18.429Z","dependency_job_id":null,"html_url":"https://github.com/artemeff/eql","commit_stats":{"total_commits":29,"total_committers":6,"mean_commits":4.833333333333333,"dds":0.4482758620689655,"last_synced_commit":"ae18e87d8b4a86307c55fb45856991336f0d8d3b"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artemeff%2Feql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artemeff%2Feql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artemeff%2Feql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artemeff%2Feql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artemeff","download_url":"https://codeload.github.com/artemeff/eql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284953,"owners_count":20913704,"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-04T00:01:18.596Z","updated_at":"2025-04-05T04:14:38.393Z","avatar_url":"https://github.com/artemeff.png","language":"Erlang","readme":"### eql [![Hex.pm](https://img.shields.io/hexpm/v/eql.svg)](https://hex.pm/packages/eql)\n\n---\n\nErlang with SQL, inspired by [yesql](https://github.com/krisajenkins/yesql).\n\n---\n\n### description\n\nSuppose we have a database with a list of users, in Erlang we can use simple ORM ([boss_db](https://github.com/ChicagoBoss/boss_db), [texas](https://github.com/emedia-project/texas)), SQL builders ([sqerl](https://github.com/devinus/sqerl), [mekao](https://github.com/ddosia/mekao)) or write SQL queries in Erlang code like this:\n\n```erlang\nget_users(Conn) -\u003e\n    pgsql:squery(Conn, \"SELECT * FROM users;\").\n```\n\nOr something like that. __yesql__ proposes to write SQL queries by your hands, but do it comfortably. Because most of ORM and SQL builders adds some [accidental complexity](http://en.wikipedia.org/wiki/No_Silver_Bullet) to your software, ORM or builder should parse your code into SQL and then your RDBMS should parse SQL, also write a complex query in ORM - is pure hell, sometimes. That's why you should use pure SQL with some handy features, like that:\n\n```sql\n-- Get all users from database\n-- :get_all_users\nSELECT *\nFROM users;\n\n-- Just some description here\n-- :get_user_by_id\nSELECT *\nFROM users\nWHERE id = ?\n\n-- Just some description here\n-- :get_by_id\nSELECT *\nFROM :table\nWHERE id = ?\n```\n\nIn Erlang you can use these queries like functions:\n\n```erlang\n\u003e {ok, Queries} = eql:compile(\"queries/user.sql\"). % with path to your queries file\n\u003e {ok, Q1} = eql:get_query(get_all_users, Queries).\n\u003e {ok, Q2} = proplists:get_value(get_user_by_id, Queries).\n\u003e {ok, Q3} = eql:get_query(get_by_id, Queries, [{table, \"some_table\"}]).\n\u003e Q1.\n%\u003e \u003c\u003c\"SELECT * FROM users;\"\u003e\u003e\n\u003e Q2.\n%\u003e \u003c\u003c\"SELECT * FROM users WHERE id = ?\"\u003e\u003e\n\u003e Q3.\n%\u003e [\u003c\u003c\"SELECT * FROM \"\u003e\u003e,\"some_table\",\u003c\u003c\" WHERE id = ?\"\u003e\u003e]\n```\n\n*Note*: The named parameters like `:table` in the example above are not sanitized, so can be dangerous.\n\n---\n\n### Not only for SQL\n\nThis library can provide anything you want with separated sections in file, eg for ENV-specific configuration:\n\n```erlang\n-- ./env.config file\n-- :dev\n[{host, \"app.dev\"}].\n\n-- :prod\n[{host, \"app.com\"}].\n```\n\nWe can parse this file like SQL queries (but comments with `%` isn't supported yet, you can create PR for this feature :)).\n\n```erlang\n\u003e {ok, Config} = eql:compile(\"./env.config\").\n%\u003e {ok,[{prod,\u003c\u003c\"[{host, \\\"app.com\\\"}].\"\u003e\u003e},\n        {dev,\u003c\u003c\"[{host, \\\"app.dev\\\"}].\"\u003e\u003e}]}\n```\n\n`eql:compile/1` returns proplist of defined env configurations and we can parse each of them with simple helper:\n\n```erlang\n-module(config_helper).\n-export([load/2]).\n\nload(Env, Config) -\u003e\n    parse(scan(proplists:get_value(Env, Config))).\n\nscan(undefined) -\u003e\n    undefined;\nscan(IoList) -\u003e\n    erl_scan:string(lists:flatten(io_lib:format(\"~s\", [IoList]))).\n\nparse({ok, Tokens, _}) -\u003e\n    erl_parse:parse_term(Tokens);\nparse(_) -\u003e\n    undefined.\n```\n\nAnd use it like:\n\n```erlang\n\u003e config_helper:load(prod, Config).\n%\u003e {ok,[{host,\"app.com\"}]}\n\u003e config_helper:load(dev, Config).\n%\u003e {ok,[{host,\"app.dev\"}]}\n```\n\nThis module already exist and named [`eql_config`](/src/eql_config.erl) for you.\n\n---\n\n### Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\nIf you make changes to the neotoma PEG file, `src/eql_parse.peg` you must run `rebar3 as dev compile` to rebuild `src/eql_parse.erl`, then run `rebar3` commands like `compile` and `eunit` as normal.\n","funding_links":[],"categories":["Text and Numbers"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartemeff%2Feql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartemeff%2Feql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartemeff%2Feql/lists"}