tonsky /datascript
Immutable database and Datalog query engine for Clojure, ClojureScript and JS
★ 5,798⑂ 319👁 140⑃ 168● 325▤ 129
+0
Daily
5,798
stars
319
forks
140
watchers
168
prs
325
issues
129
releases
README
What if creating a database would be as cheap as creating a Hashmap?
An immutable in-memory database and Datalog query engine in Clojure and ClojureScript.
DataScript is meant to run inside the browser. It is cheap to create, quick to query and ephemeral. You create a database on page load, put some data in it, track changes, do queries and forget about it when the user closes the page.
DataScript databases are immutable and based on persistent data structures. In fact, they’re more like data structures than databases (think Hashmap). Unlike querying a real SQL DB, when you query DataScript, it all comes down to a Hashmap lookup. Or series of lookups. Or array iteration. There’s no particular overhead to it. You put a little data in it, it’s fast. You put in a lot of data, well, at least it has indexes. That should do better than you filtering an array by hand anyway. The thing is really lightweight.
The intention with DataScript is to be a basic building block in client-side applications that needs to track a lot of state during their lifetime. There’s a lot of benefits:
- Central, uniform approach to manage all application state. Clients working with state become decoupled and independent: rendering, server sync, undo/redo do not interfere with each other.
- Immutability simplifies things even in a single-threaded browser environment. Keep track of app state evolution, rewind to any point in time, always render consistent state, sync in background without locking anybody.
- Datalog query engine to answer non-trivial questions about current app state.
- Structured format to track data coming in and out of DB. Datalog queries can be run against it too.
Latest version
clj
;; lein
[datascript "1.8.1"]
clj
;; deps.edn
datascript/datascript {:mvn/version "1.8.1"}
Important! If you are using shadow-cljs, add
clj
:compiler-options {:externs ["datascript/externs.js"]}
to your build (see 432 298 216)
Resources
Support:
- Join datascript on Clojurians Slack (grab invite here)
Books:
- Learning ClojureScript has a chapter on DataScript
Docs:
- API Docs
- docs/queries.md
- docs/tuples.md
- docs/storage.md
- Getting started
- Tutorials
- Tips & tricks
- Triple Stores overview
- Quick tutorial into Datalog
Posts:
- How DataScript fits into the current webdev ecosystem
- DataScript internals explained
- Sketch of client/server reactive architecture
Talks:
- “Frontend with Joy” talk (FPConf, August 2015): video in Russian
- “Programming Web UI with Database in a Browser” talk (PolyConf, July 2015): slides, video
- “DataScript for Web Development” talk (Clojure eXchange, Dec 2014): slides, video
- “Building ToDo list with DataScript” webinar (ClojureScript NYC, Dec 2014): video, app
- DataScript hangout (May 2014, in Russian): video
Projects using DataScript:
- Roam Research, a note-taking graph database
- LogSeq, a local-first, non-linear, outliner notebook
- Athens Research, a tool for networked thought
- Hulunote, a tool for netwTop issues
#52Idents?31 comments · 2015-01-28#132Idea for a reactive and faster alternative to Datascript28 comments · 2015-11-25#248Storing raw JS objects and querying according to pointer equality `===`20 comments · 2018-01-24#135Documentation?12 comments · 2015-12-05#389Transactable entities11 comments · 2021-04-01#244Self-hosted ClojureScript compatibility11 comments · 2017-12-18#351VAET index10 comments · 2020-06-02#200Allow non-numbers as entity ids10 comments · 2016-12-21
Discussions
#485Does it work with clojure squint, clojure dart or babashka0 comments · 2025-03-12#444How to use a dynamic attribute?2 comments · 2023-01-16#371Welcome to DataScript Discussions!0 comments · 2020-12-09
Latest release
1.8.1 1.8.1 2026-08-15- Re-enable transient indices during transact 373