{"id":19123789,"url":"https://github.com/mauricioszabo/relational-clojure","last_synced_at":"2025-10-05T16:33:00.242Z","repository":{"id":136382337,"uuid":"56471301","full_name":"mauricioszabo/relational-clojure","owner":"mauricioszabo","description":"Relational port for Clojure","archived":false,"fork":false,"pushed_at":"2017-04-23T17:36:40.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-09T05:31:48.438Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mauricioszabo.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-18T02:36:50.000Z","updated_at":"2016-04-18T02:37:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f52169b-05ff-474d-a11f-72e0d4754909","html_url":"https://github.com/mauricioszabo/relational-clojure","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/mauricioszabo%2Frelational-clojure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioszabo%2Frelational-clojure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioszabo%2Frelational-clojure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioszabo%2Frelational-clojure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mauricioszabo","download_url":"https://codeload.github.com/mauricioszabo/relational-clojure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232314015,"owners_count":18504026,"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-11-09T05:27:11.762Z","updated_at":"2025-10-05T16:32:55.223Z","avatar_url":"https://github.com/mauricioszabo.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Relational Clojure\n\nAn experiment to abstract SQL fragments into Clojure constructions.\n\n## Usage\n\n*WARNING - Not working yet!*\n\nMost constructions are aliased in the `sql` namespace. You can run with:\n\n```clojure\n(use '[relational.sql])\n\n; SELECT \"foo\".\"bar\"\n(sql/select (sql/attribute \"foo\" \"bar\"))\n\n; WHERE \"foo\".\"bar\" = 'baz' OR \"foo\".\"bar\" = 'quox'\n(sql/where\n  (sql/or\n    (sql/= (sql/attribute \"foo\" \"bar\") \"baz\")\n    (sql/= (sql/attribute \"foo\" \"bar\") \"quox\")))\n\n; NILs are supported - they are ignored\n(sql/where nil) ; =\u003e \"\"\n(sql/where\n  (sql/or\n    (sql/= (sql/attribute \"foo\" \"bar\") \"baz\")\n    nil)) ; =\u003e WHERE \"foo\".\"bar\" = 'baz'\n```\n\nBut it is tedious to do this all the time. So, we have a bunch of macros in `relational.core` to help:\n\n```clojure\n(use '[relational.core :refer :all])\n\n; SELECT \"foo\".\"bar\" FROM \"foo\" WHERE \"foo\".\"bar\" = 'baz'\n(query\n  (select :foo.bar)\n  (from :foo)\n  (where (= :foo.bar \"baz\")))\n```\n\nBut, Relational constructions doesn't return strings. They return `IPartial`s, constructions that respond to `partial-fn`. These return a function that expect a single parameter - `db` - that are hashes used to configure a database connection.\n\nWhen we run this function, it'll return a tuple (a vector with 2 positions) - a SQL string with placeholders `?`, and another vector with the parameters.\n\n```clojure\n(use '[relational.core :refer :all])\n\n(db-for mysql :adapter :mysql\n              :host \"localhost\"\n              :user \"root\")\n\n(db-for pg :adapter :postgresql\n           :host \"localhost\"\n           :user \"postgres\")\n\n; SELECT \"foo\".\"bar\" FROM \"foo\" WHERE \"foo\".\"bar\" = 'baz'\n(def q (query\n         (select :foo.bar)\n         (from :foo)\n         (where (= :foo.bar \"baz\"))))\n\n(def p (partial-fn q))\n\n; =\u003e [\"SELECT `foo`.`bar` FROM `foo` WHERE `foo`.`bar` = ?\" [\"baz\"]]\n(p mysql)\n\n; =\u003e [\"SELECT \\\"foo\\\".\\\"bar\\\" FROM \\\"foo\\\" WHERE \\\"foo\\\".\\\"bar\\\" = ?\" [\"baz\"]]\n(p pg)\n```\n\n## Compositions\n\nTODO\n\n## License\n\nCopyright © 2016 Maurício Szabo\n\nDistributed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauricioszabo%2Frelational-clojure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmauricioszabo%2Frelational-clojure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauricioszabo%2Frelational-clojure/lists"}