Giter Club home page Giter Club logo

Comments (6)

ul avatar ul commented on May 10, 2024

+1 to proposal weight ;-)

from datascript.

tonsky avatar tonsky commented on May 10, 2024

DataScript DB is a persistent data structure. Database mutation is build in terms of pure functions. You can get full DataScript experience without touching atom/conn/listeners part: check out empty-db and with. For example, with works just like transact! except that it takes db and returns db, being, in fact, a pure function. Queries run over plain DB values, not over connections.

There’s then a thin layer (optional, in fact), wrapping this DB into an atom (literally) and providing transact and listener facilities. It’s build on top of the same immutable, pure primitives.

Database swapping is atomic, there’s no “temporary db states”. Atom is atomically swapped from db-before to db-after when using transact!.

You can build your own mutation layer quite simply, just by using (swap! db-atom with ...) instead of transact!. You’ll lose txReports, but overall experience will be the same.

So the only question remains, why TxReports?

Atom’s watch fn gives you just value before and after, but it does not capture the change. TxReport solves exactly that problem: when using transact or transact!, it captures normalized deltas from db-before to db-after. Why may we need that?

First, to monitor DB: you can run Datalog queries over tx-data to know when the part you’re interested in have changed. It’s much faster than run the same query over full DB. (See here, “Transaction format happens to match database format...”).

Second, it makes a great server sync format. You may add generic listener to DB that will mirror all changes to server backend for durability.

There’s no incidental complexity to it. It’s actually just more detailed version of atom, where not only value before and value after, but change itself is also data. All the data-oriented benefits apply.

from datascript.

frankiesardo avatar frankiesardo commented on May 10, 2024

Thank you for taking the time to state your design ideas so clearly, I think it will make a great start for a datascript wiki page 👍

I generally agree with everything you said and probably I should have read your code more carefully and expressed myself better. As you say, transact!, create-conn and the likes are a thin layer on top of a persistent data structure: maybe the usage examples could help a future reader first introducing the purely functional operations on datascript and leaving the atom manipulation at the end of the README as an optional nice-to-have.

I especially liked your explanation for TxReports. But what if the latest tx-data is included as yet another key inside datascript data structure? That way every new database version would be self-explicative.

from datascript.

ul avatar ul commented on May 10, 2024

m.b. not key inside data structure, but in metadata?

from datascript.

frankiesardo avatar frankiesardo commented on May 10, 2024

Well yeah, alongside av, max-eid and the other keys

from datascript.

tonsky avatar tonsky commented on May 10, 2024

What’s wrong with the way it is right now?

from datascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.