{"id":13760428,"url":"https://github.com/wotbrew/relic","last_synced_at":"2025-10-22T01:54:33.382Z","repository":{"id":44570680,"uuid":"390014492","full_name":"wotbrew/relic","owner":"wotbrew","description":"Functional relational programming for Clojure(Script).","archived":false,"fork":false,"pushed_at":"2024-08-14T13:30:03.000Z","size":1756,"stargazers_count":408,"open_issues_count":4,"forks_count":7,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-28T13:23:29.219Z","etag":null,"topics":["clojure","dataflow","incremental-view-maintenance","logic","relational-algebra","relations","sql"],"latest_commit_sha":null,"homepage":"https://www.wotbrew.com/relic","language":"Clojure","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/wotbrew.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}},"created_at":"2021-07-27T14:29:21.000Z","updated_at":"2024-10-16T00:35:26.000Z","dependencies_parsed_at":"2024-01-15T04:09:37.618Z","dependency_job_id":null,"html_url":"https://github.com/wotbrew/relic","commit_stats":{"total_commits":411,"total_committers":3,"mean_commits":137.0,"dds":"0.22871046228710468","last_synced_commit":"c947dbf10fcb618f56e8416c8340057d0f43e0df"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wotbrew%2Frelic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wotbrew%2Frelic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wotbrew%2Frelic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wotbrew%2Frelic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wotbrew","download_url":"https://codeload.github.com/wotbrew/relic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224949824,"owners_count":17397239,"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":["clojure","dataflow","incremental-view-maintenance","logic","relational-algebra","relations","sql"],"created_at":"2024-08-03T13:01:10.065Z","updated_at":"2025-10-22T01:54:28.349Z","avatar_url":"https://github.com/wotbrew.png","language":"Clojure","funding_links":[],"categories":["Clojure"],"sub_categories":[],"readme":"# relic\n\n![tests](https://github.com/wotbrew/relic/actions/workflows/tests.yml/badge.svg) [![Clojars Project](https://img.shields.io/clojars/v/com.wotbrew/relic.svg)](https://clojars.org/com.wotbrew/relic)\n\n`relic` is a Clojure(Script) data structure that provides the functional relational programming model described by the [tar pit](http://curtclifton.net/papers/MoseleyMarks06a.pdf) paper.\n\n## Why\n\n\u003e The relational view (or model) of data ... appears to be superior in several respects to the graph or network model .... It provides a means of describing data with its natural structure only-that is, without superimposing any additional structure for machine representation\npurposes - Codd, A Relational Model of Data for\nLarge Shared Data Banks\n\n### Support for relational data representation\n\nProgramming with maps becomes less ergonomic as soon as you have to deal with more than one collection of them at a time, so often they are over structured into trees that limit their use in different contexts.\n\nNormalized relations are a more principled way to represent our collections of maps. There are some tools for working with relations in `clojure.set`, and they help.\n\nBut `clojure.set` has little to say about how groups of relations should be represented, and indexes are either created for each join, or not used at all.\n\n### Declarative data processing\n\nData processing pipelines [could be defined as queries](https://nchammas.com/writing/data-pipeline-materialized-view), a specification of the result rather than the steps - but you need mechanisms that can do this efficiently, particularly for partial updates.\n\n### Declarative relational constraints \n\nIt is often important to rule out invalid states, there are many tools for doing this to single maps or collections, but specifying constraints that exist in the space of relationships is often on the programmer to do manually.\n\nIt'd be nice to have a constraint language which was [more like a query](https://nchammas.com/writing/query-language-constraint-language).\n\n### Reactive programming\n\nIn interactive applications, the system must respond to user input. You have the problem of invalidation - that is, how do you make sure dependent computations are re-run in response to the state of the program changing.\nre-frame does this with its subscriptions, but getting good performance if you have to invalidate say, an aggregate - is difficult and on you.\n\n### Reducing accidental complexity\n\n`relic` is trying to reduce complexity, an experiment that allows you to program with normalized data, declarative query, constraints and data processing, and retain good-enough performance.\n\n## Features\n\n- Fully featured in-memory database with indexed SQL style [query](https://www.wotbrew.com/relic/query).\n- Integrated and embedded in clojure, use clojure [functions](https://www.wotbrew.com/relic/expr) in queries, build queries with clojure.\n- [Materialized views](https://www.wotbrew.com/relic/materialization) with incremental maintenance.\n- Make invalid states illegal with [constraints](https://www.wotbrew.com/relic/constraints).\n- [Reactive](https://www.wotbrew.com/relic/change-tracking), allowing efficient integration with react, bind components to materialized queries and remain responsive at 60fps.\n\n`relic` only targets in-memory use cases, for this kind of thing at scale consider: [materialize](https://github.com/MaterializeInc/materialize).\n\n## Installation\n\nWith `leiningen`\n\n```clojure\n[com.wotbrew/relic \"0.1.7\"]\n```\n\nWith `clojure` (`deps.edn`)\n\n```clojure \ncom.wotbrew/relic {:mvn/version \"0.1.7\"}\n```\n\n## Documentation\n\nSee [documentation](https://www.wotbrew.com/relic) for a detailed reference.\n\n## Pitch\n\nDo you suffer from _map fatigue_? [[1]](http://timothypratley.blogspot.com/2019/01/meander-answer-to-map-fatigue.html)\n\n![despair](doc/tar2.png)\n\nDid you try [meander](https://github.com/noprompt/meander), [core.logic](https://github.com/clojure/core.logic), [datascript](https://github.com/tonsky/datascript) and every graph-map-database under the sun but still do not feel [out of the tar pit](http://curtclifton.net/papers/MoseleyMarks06a.pdf)?\n\n![in the tar pit](doc/tar.jpeg)\n\nAre you tired of writing mechanical wiring and glue? That has *nothing* to do with your actual business logic?\n\n`relic` might help, but it's not a medical professional. It's a functional relational programming library.\n\nDefinitely not at all like the other in-memory databases in clojure. This time it is different, really.\n\n## Brief tour\n\nI like to use `rel` as an alias.\n\n```clojure\n(require '[com.wotbrew.relic :as rel])\n```\n\nThis is a query, lets find some bob's.\n\n```clojure \n [[:from :Customer]\n  [:where [= :name \"bob\"]]]\n ```\n\nYou can refine queries by just adding elements to the vector.  All your favorites are here, filtering (`:where`), computing columns (`:extend`), joins (`:join` \u0026 `:left-join`), grouping and aggregation (`:agg`) and more.\n\n```clojure \n[[:from :Customer]\n [:where [= :name \"bob\"]]\n [:extend [:greeting [str \"Hello, \" :name \"!\"]]]\n```\n\nBecause queries are just vectors, they just sort of lounge around being values. To put them to work we have to feed some data into relic.\n\n`relic` databases are boring clojure maps. Prepare yourself:\n\n```clojure \n(def db {})\n```\n\nSee, boring.\n\nYou manipulate your database with the [`transact`](https://www.wotbrew.com/relic/transact) function. This returns a new database with the transaction applied. Plain old functional programming, no surprises.\n```clojure \n(def db (rel/transact {} [:insert :Customer {:name \"bob\"} {:name \"alice\"}])\n\ndb \n;; =\u003e\n{:Customer #{{:name \"bob\"}, {:name \"alice\"}}}\n```\n\nNow we have some state, we can ask questions of relic, as you would a SQL database.\n\n```clojure \n(rel/q db :Customer)\n;; =\u003e \n({:name \"bob\"}, {:name \"alice\"})\n\n(rel/q db [[:from :Customer] [:where [= :name \"bob\"]]]) \n;; =\u003e \n({:name \"bob\"})\n\n(rel/q db [[:from :Customer] [:agg [] [:avg-name-len [rel/avg [count :name]]]]])\n;; =\u003e \n({:avg-name-len 4})\n```\n\nOk ok, neat but not _cool_.\n\nAhhhh... but you don't understand, `relic` doesn't just evaluate queries like some kind of cave man technology - it is powered by a __data flow graph__.\n`relic` knows when your data changes, and it knows how to modify dependent relations in a smart way.\n\nYou can materialize any query such that it will be maintained for you as you modify the database. In other words `relic` has __incremental materialized views__.\n\n```clojure \n(rel/mat db [[:from :Customer] [:where [= :name \"bob\"]]])\n;; =\u003e returns the database, its value will be the same, but internally some machinery will have been allocated.\n{:Customer #{{:name \"bob\"}, {:name \"alice\"}}}\n```\n\n`mat` will return a new _database_, against which materialized queries will be instant, and __as you change data in tables, those changes will flow to materialized queries automatically.__\n\nYou can do more than query and materialize with relic, you can [react to changes](https://www.wotbrew.com/relic/change-tracking), use [constraints](https://www.wotbrew.com/relic/constraints) and [more](https://www.wotbrew.com/relic).\n\nIf you read the tarpit paper, you might find this [real estate example](https://github.com/wotbrew/relic/blob/master/dev/examples/real_estate.clj) informative.\n\nAnother example demonstrating usage in the browser can be found in [cljidle](https://github.com/wotbrew/relic/blob/master/dev/examples/cljidle).\n\nFor further reading, see the [docs](https://www.wotbrew.com/relic).\n\n## Related libraries\n\n- [core.logic](https://github.com/clojure/core.logic) \n- [datascript](https://github.com/tonsky/datascript)\n- [clara-rules](https://github.com/cernerel/clara-rules)\n- [odoyle-rules](https://github.com/oakes/odoyle-rules)\n- [fyra](https://github.com/yanatan16/fyra)\n- [meander](https://github.com/noprompt/meander)\n- [doxa](https://github.com/ribelo/doxa)\n- [clj-3df](https://github.com/sixthnormal/clj-3df)\n\n## Thanks \n\n- [@bradb](https://github.com/bradb) for early sketch sessions\n- [@tom-riverford](https://github.com/tom-riverford) for indulging me\n- [@riverford](https://github.com/riverford) for being the greatest green grocers in devon that uses clojure\n\n## LETS GO\n\n![lets go](doc/tar3.png)\n\n`#relic` on clojurians\n\nEmail and raise issues. PR welcome, ideas and discussion encouraged.\n\n## License\n\nCopyright 2022 Dan Stone (wotbrew)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwotbrew%2Frelic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwotbrew%2Frelic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwotbrew%2Frelic/lists"}