What does HackerNews think of datascript?

Immutable database and Datalog query engine for Clojure, ClojureScript and JS

Language: Clojure

#2 in Clojure
#1 in Database
ICYMI, there's an excellent interactive introduction to `datalog` that's referenced in the article's references.[0]

Last time I used `datalog` was years ago, I was developing an internal interactive tool that was used to compare different approaches to solving a certain problem at my employer. I used `datascript`[1] by way of clojurescript to store all experiment data and then interrogated the `datascript` DB via `datalog`. This is something I always remember fondly.

[0] https://www.learndatalogtoday.org/ [1] https://github.com/tonsky/datascript

Datascript is the open source analog for Clojure, ClojureScript and JS: https://github.com/tonsky/datascript
I think the Roam Research style backlinked knowledge management apps are directly enabled by datascript.

Two "copy cats" (not meant to be derogatory) of Roam that are open source are: https://github.com/logseq/logseq https://github.com/athensresearch/athens

The underlying in memory datalog style database that can run in the browser that enables these apps https://github.com/tonsky/datascript

This look nice !

Datascript seems to be another Datalog engine (in memory only)

https://github.com/tonsky/datascript

Minor correction, I don't think Datomic is used. I believe it uses a variation of DataScript and in turn DataLog for queries. Whereas Datomic is a DB which is also based on and uses DataLog queries.

Either way, super powerful.

Refs: https://en.m.wikipedia.org/wiki/Datalog https://github.com/tonsky/datascript https://www.datomic.com/

Interesting & available libraries implementing parts of this particular vision (mentioned in the talk):

- Google's Firebase (meh, though maybe Supabase is mature enough by now to replace this suggestion?)

- Tinybase: https://tinybase.org

- sql.js (SQLite compiled to js): https://sql.js.org/

But there's no single stack available (yet). I'm suprised Nikita didn't mention datascript here (https://github.com/tonsky/datascript) given the neat compatibility it offers with other datalog databases, but maybe he feels it's too niche/immature?

It’s fascinating to see so many different parties converging on Datalog for reactive apps & UI.

- There are several such talks at https://www.hytradboi.com/ (happening this Friday)

- Roam Research and its clones Athens, Logseq, use Datascript / ClojureScript https://github.com/tonsky/datascript

- differential-datalog isn’t an end-to-end system, but is highly optimized for quick reactivity https://github.com/vmware/differential-datalog

- Datalog UI is a Typescript port of some of differential-datalog’s ideas https://datalogui.dev/

I think an under appreciated aspect of Datalog is as a pure specification language for relationships. Schema languages like GraphQL specify a relation between types exists, but not how it is computed. Prisma and other ORM DSLs like ActiveRecord do a better job specifying how to compute a relation from SQL tables, but support only a few strict computation types that can be modeled using SQL JOIN on columns.

Datalog lets you purely specify arbitrarily complex logical relationships between data types. Even if you were to only use Datalog as a rules engine at test time, it could still be quite powerful for validating logic implemented in different languages on the same data model, to say keep your Typescript, Kotlin and Swift logic in sync.

There's Datascript[0] and Datomic[1]. While not "identical", they are definitely complimentary. There's a (now defunct) library[2] for keeping them in sync too.

1: https://github.com/tonsky/datascript 2: https://www.datomic.com/ 3: https://github.com/metasoarous/datsync

The work is funded by a Clojure community group (and a Clojure-using company), and Tonsky has written a bunch of awesome other Clojure (see DataScript[1]).

So it seems as though the decision to use Clojure was not made for technical reasons, but it's not exactly arbitrary.

[1] https://github.com/tonsky/datascript

Depends on your use case

I would suggest soufflé (https://souffle-lang.github.io/) if you're batching data through for static analysis.

DDLog (https://github.com/vmware/differential-datalog) if you want a rule-engine within your interactive application, to encode decision procedures and business rules.

If you actually want this to drive the views of a (web-)application, I don't think we're really there yet. We have to wait at least for the next generation of developments. But you can give it a try with datascript https://github.com/tonsky/datascript

Author here. I started it as a side project to have a local-first, org-mode outliner web app to use on my phone. I chose Clojure/Clojurescript because I'm more familiar with both compared to Javascript/Typescript. Several things I like a lot about Clojure/Clojurescript: Data-Oriented Programming, all three (logseq, roam, athens) use Datascript, which is an in-memory database and Datalog query engine. REPL (as other lisp languages) Clojure is very stable, I can run all my old projects without any issues. Also, I don't reverse engineering the Roam code(it'll cost more time for us), Logseq is hugely inspired by Roam Research, Org Mode, TiddlyWiki, Workflow.

- Datascript: https://github.com/tonsky/datascript

Sounds like DataScript [0] could be a good fit for you. The Datalog query language is very powerful for writing recursive rules.

[0] https://github.com/tonsky/datascript

A lot of Clojure libraries will be described as Clojure(Script) libraries which means they run on both Java and JS usually with no interface changes here are some examples: https://github.com/tonsky/datascript https://github.com/Engelberg/instaparse https://github.com/wilkerlucio/pathom

Interop with hosts is a core feature of the language so it feels natural to reach for it when you need it and it's easy to write code that handles multiple runtimes but 95% of the time maybe more you don't need explicit runtime features

For Clojure, there is Datomic[0] (a DB with S-expression Datalog) and DataScript[1] (in memory Datalog for browser) which has a fair amount of usage. Also, there's a bitemporal database use Datalog name Crux[2] seems to be quite promising.

[0] https://www.datomic.com/ [1] https://github.com/tonsky/datascript [2] https://opencrux.com/

I would be remiss if I didn't mention something from clojurescript land that accomplishes something similar: https://github.com/tonsky/datascript

Datascript allows you to write datalog queries in ClojureScript(and JavaScript) that operate on a b+ tree maintained by the library. It includes first class relationships and unique keys.

If you need to manage state and want to focus on functions instead of objects (classes), try ClojureScript - especially in combination with [DataScript](https://github.com/tonsky/datascript), an immutable database and Datalog query engine. Clojure/ClojureScript's persistent, immutable memory model makes it much nicer for reasoning about state.

Maybe I'm just a dinosaur, but I can't keep up with all the changes to JavaScript, whereas ClojureScript compiles to ECMAScript 3 and the syntax hasn't changed since its release 12 years ago.

This is actually fairly common in Clojure annd Clojure script. Sometimes using the Datomic DB as a backend for it.

This is an older presentation but its all about doing Datalog from the client to the DB.

See: https://www.youtube.com/watch?v=aI0zVzzoK_E

But if you go threw the Clojure world, there is Datalog all over the place, both client and server. Check out Datascript:

https://github.com/tonsky/datascript

This full-stack framework: http://book.fulcrologic.com/

Depending on the stack, you can use some open source libraries. Datascript is quite robust, and useable from javascript/clojurescript. https://github.com/tonsky/datascript
A more common solution includes using Datascript[1] as the client side DB and then using something like Posh[2] or Datsync[3] to handle query/pull subscription changes.

[1]: https://github.com/tonsky/datascript

[2]: https://github.com/mpdairy/posh

[3]: https://github.com/metasoarous/datsync

Totally not saying "you're holding it wrong", but maybe once you're more than a few couple levels deep into a nested map it's time to look at an in memory db like [Datascript](https://github.com/tonsky/datascript)? Actual Datalog queries can replace get-in vectors growing out of hand, and you also get better mutations with transactions.
> Unfortunately I just haven't been able to figure out how to do a left outer join (or if that's even the right approach in Prolog :-)

That is probably my main issue with SQL: That the names of some of the keywords are very table-ish and not very semantic; like LEFT OUTER JOIN. I mean, if we have some facts, like how old people are, and what they like to eat, then what does it even mean that any of those facts is to the left or on the inside of another? I can't fit that into my brain.

But let's take an example. We have these sets of facts (which, if they were in SQL, would be in two different tables):

    age(alice, 20).           
    age(beatrice, 30).        
    age(charlie, 90).                                   
    likes(alice, carrots).    
    likes(alice, chips).      
    likes(charlie, crumpets). 
Then an INNER JOIN would probably be like:

    age(Name,Age), likes(Name, Something).
This can be read as "What is the age of anyone, who like something?" (or more absurdly, "What does anyone, who has an age, like?", depending on what variable we focus on.)

I'm probably getting this wrong, but if we wanted LEFT OUTER JOIN it would be more like:

    age(Name,Age); likes(Name, Something).
Which is more like "What's all people's ages, and what does anyone like?"

In Prolog, the comma means 'and', and the semicolon means 'or', so in the second query anyone, who has an age but doesn't like anything, will still be included. In this query, that would be Beatrice. That's a bit like a LEFT OUTER JOIN, isn't it?

> I find the idea of a simple Prolog, like a Datalog, very intriguing as a potential simple query engine for apps in mainstream languages–not having to worry about the maps, filters, reduces, flatmaps, and all the other operations we have to do to coax data into the right shapes in line-of-business apps.

Seen DataScript?[0] I think MiniKanren has also been implemented in most languages. I like how Prolog "forces" a declarative style though.

[0]: https://github.com/tonsky/datascript

There is datascript, which has a foss implementation of datascript (with nice performance)

https://github.com/tonsky/datascript And this (deprecated) project, that translate datalog to SQL(lite) https://github.com/mozilla/mentat

"Datalog is a declarative logic programming language that syntactically is a subset of Prolog." [1]

"Datomic is a distributed database and implementation of Datalog.". Datomic seems to be quite succesful [2].

Related to datomic, I'm trying to learn Datascript these days ("An immutable in-memory database and Datalog query engine in Clojure and ClojureScript.") [3].

1: https://en.wikipedia.org/wiki/Datalog

2: https://www.datomic.com/customers.html

3: https://github.com/tonsky/datascript

Yes, Datomic is the killer app for Clojure [^1]. Have a look at Datascript[^2] and Mozilla's Mentat[^3], which is basically an embedded Datomic in Rust.

Hickey's Spec-ulation keynote is probably his most controversial talk, but it finally swayed me toward dynamic typing for growing large systems: https://www.youtube.com/watch?v=oyLBGkS5ICk

The Clojure build ecosystem is tough. Ten years ago, I could not have wrangled Clojure with my skillset - it's a stallion. We early adopters are masochists, but we endure the pain for early advantages, like a stable JavaScript target, immutable filesets and hot-reloading way before anyone else had it.

Is it worth it? Only if it pays off. I think ClojureScript and Datomic are starting to pay off, but it's not obvious for who - certainly not very ever organisation.

React Native? I tore my hair out having to `rm -rf ./node-modules` every 2 hours to deal with breaking dependency issues.

Whenever I try to use something else (like Swift), I crawl back to Clojure for the small, consistent language. I don't think Clojure is the end-game, but a Lisp with truly immutable namespaces and data structures is probably in the future.

[^1]: In 2014 I wrote down "Why Clojure?" - http://petrustheron.com/posts/why-clojure.html [^2]: https://github.com/tonsky/datascript [^3]: https://github.com/mozilla/mentat

https://www.datomic.com/get-datomic.html starter version

https://github.com/tonsky/datascript Datascript is also neat, it's an in-browser DB with datalog query syntax. There's some neat stuff possible with om.next + datascript: https://github.com/omcljs/om/wiki/DataScript-Integration-Tut...

For anyone interested in exploring the datomic model, there is a great ClojureScript in-memory implementation called datascript (https://github.com/tonsky/datascript) by Nikita Prokopov.
If you are wondering why you would want to dive in, let me offer another good reason: there is Datascript (https://github.com/tonsky/datascript), which puts a good subset of Datalog inside your client-side browser app.

I found it very useful for dealing with relational data in browser apps.

We use Datalog every day in a React-Native application, via the datascript db (https://github.com/tonsky/datascript). Has been a very positive experience so far.

Thinking in "facts" / binary relations is itself a refreshing approach.

There's a typo in your datascript url (s/k are switched). Here's the corrected one: https://github.com/tonsky/datascript