https://github.com/wotbrew/relic Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} wotbrew / relic Public * Notifications * Fork 3 * Star 201 Functional relational programming for Clojure(Script). www.wotbrew.com/relic License MIT license 201 stars 3 forks Star Notifications * Code * Issues 1 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights wotbrew/relic This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 6 branches 6 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/w] Use Git or checkout with SVN using the web URL. [gh repo clone wotbre] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @wotbrew wotbrew Add index pick test for user index over more than one col ... c947dbf Jan 13, 2023 Add index pick test for user index over more than one col c947dbf Git stats * 417 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows tests & badge January 5, 2022 13:51 dev typo in docstring February 2, 2022 17:38 doc brief note about empty rel February 4, 2022 20:30 src/com/wotbrew Fix missing case when using unique indexes on joins over more than on... January 13, 2023 20:40 test/com/wotbrew Add index pick test for user index over more than one col January 13, 2023 20:45 .gitignore explicit idea ignore August 15, 2022 13:06 CHANGELOG.md 0.1.5 February 8, 2022 10:42 LICENSE cc year January 15, 2022 09:32 README.md tweaks for the tweak god February 8, 2022 12:39 cljs.html mui styles for cljs testing December 22, 2021 22:34 deploy-docs.sh doc deploy script December 22, 2021 11:29 mkdocs.yml add demos section to docs February 2, 2022 17:17 package-lock.json include sourcemaps for dev February 6, 2022 23:50 package.json include sourcemaps for dev February 6, 2022 23:50 project.clj snapshot bump February 8, 2022 10:44 shadow-cljs.edn cljidle February 2, 2022 16:53 View code [ ] relic Why Support for relational data representation Declarative data processing Declarative relational constraints Reactive programming Reducing accidental complexity Features Installation Documentation Pitch Brief tour Related libraries Thanks LETS GO License README.md relic tests Clojars Project status: alpha, major breaking changes unlikely, minor ones likely relic is a Clojure(Script) data structure that provides the functional relational programming model described by the tar pit paper. Why 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 purposes - Codd, A Relational Model of Data for Large Shared Data Banks Support for relational data representation Programming 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. Normalized 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. But 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. Declarative data processing Data processing pipelines could be defined as queries, a specification of the result rather than the steps - but you need mechanisms that can do this efficiently, particularly for partial updates. Declarative relational constraints It 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. It'd be nice to have a constraint language which was more like a query. Reactive programming In 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. re-frame does this with its subscriptions, but getting good performance if you have to invalidate say, an aggregate - is difficult and on you. Reducing accidental complexity 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. Features * Fully featured in-memory database with indexed SQL style query. * Integrated and embedded in clojure, use clojure functions in queries, build queries with clojure. * Materialized views with incremental maintenance. * Make invalid states illegal with constraints. * Reactive, allowing efficient integration with react, bind components to materialized queries and remain responsive at 60fps. relic only targets in-memory use cases, for this kind of thing at scale consider: materialize. Installation With leiningen [com.wotbrew/relic "0.1.5"] With clojure (deps.edn) com.wotbrew/relic {:mvn/version "0.1.5"} Documentation See documentation for a detailed reference. Pitch Do you suffer from map fatigue? [1] despair Did you try meander, core.logic, datascript and every graph-map-database under the sun but still do not feel out of the tar pit? in the tar pit Are you tired of writing mechanical wiring and glue? That has nothing to do with your actual business logic? relic might help, but it's not a medical professional. It's a functional relational programming library. Definitely not at all like the other in-memory databases in clojure. This time it is different, really. Brief tour I like to use rel as an alias. (require '[com.wotbrew.relic :as rel]) This is a query, lets find some bob's. [[:from :Customer] [:where [= :name "bob"]]] You can refine queries by just adding elements to the vector. All your favorites are here, filtering (:where), computing columns (:extend), joins (:join & :left-join), grouping and aggregation (:agg) and more. [[:from :Customer] [:where [= :name "bob"]] [:extend [:greeting [str "Hello, " :name "!"]]] Because 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. relic databases are boring clojure maps. Prepare yourself: (def db {}) See, boring. You manipulate your database with the transact function. This returns a new database with the transaction applied. Plain old functional programming, no surprises. (def db (rel/transact {} [:insert :Customer {:name "bob"} {:name "alice"}]) db ;; => {:Customer #{{:name "bob"}, {:name "alice"}}} Now we have some state, we can ask questions of relic, as you would a SQL database. (rel/q db :Customer) ;; => ({:name "bob"}, {:name "alice"}) (rel/q db [[:from :Customer] [:where [= :name "bob"]]]) ;; => ({:name "bob"}) (rel/q db [[:from :Customer] [:agg [] [:avg-name-len [rel/avg [count :name]]]]]) ;; => ({:avg-name-len 4}) Ok ok, neat but not cool. Ahhhh... 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. relic knows when your data changes, and it knows how to modify dependent relations in a smart way. You 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. (rel/mat db [[:from :Customer] [:where [= :name "bob"]]]) ;; => returns the database, its value will be the same, but internally some machinery will have been allocated. {:Customer #{{:name "bob"}, {:name "alice"}}} 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. You can do more than query and materialize with relic, you can react to changes, use constraints and more. If you read the tarpit paper, you might find this real estate example informative. Another example demonstrating usage in the browser can be found in cljidle. For further reading, see the docs. Related libraries * core.logic * datascript * clara-rules * odoyle-rules * fyra * meander * doxa * clj-3df Thanks * @bradb for early sketch sessions * @tom-riverford for indulging me * @riverford for being the greatest green grocers in devon that uses clojure LETS GO lets go #relic on clojurians Email and raise issues. PR welcome, ideas and discussion encouraged. License Copyright 2022 Dan Stone (wotbrew) Permission 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE 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. About Functional relational programming for Clojure(Script). www.wotbrew.com/relic Topics clojure sql logic dataflow relational-algebra relations Resources Readme License MIT license Stars 201 stars Watchers 9 watching Forks 3 forks Releases 6 tags Packages 0 No packages published Contributors 2 * @wotbrew wotbrew Dan Stone * @The-Alchemist The-Alchemist The Alchemist Languages * Clojure 99.4% * Other 0.6% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.