Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

datascript example

An example using tonsky’s datascript module, which implements a datalog-style database in JavaScript. The module itself is really written in ClojureScript, but they've helpfully produced an npm-compatible module for us to use. Datalog languages are fascinating, and have some real-world use in Roam Research and Logseq.

1
2
3
4
5
6
7
8
9
10
11
12
export const datascriptExample = (async () => {
const { default: d } = await import("npm:datascript");
var schema = { "a+b+c": { ":db/tupleAttrs": ["a", "b", "c"] } };
var db = d.db_with(d.empty_db(schema), [[":db/add", 1, "a", "A"], [
":db/add",
1,
"b",
"B",
], [":db/add", 1, "c", "C"]]);
var q = "[:find ?e ?a+b+c :in $ :where [?e \"a+b+c\" ?a+b+c]]";
return d.q(q, db);
})();
October 23, 2023