3 ms·
> "find two friends with same birthdays that also have cars of same color" Wasn't that always a simple thing to do, e.g. in SQL? And how about monitoring chan
by amelius 7y ago
> "find two friends with same birthdays that also have cars of same color"
Wasn't that always a simple thing to do, e.g. in SQL?
And how about monitoring changes in the database based on a query? Is that possible and efficient?
- tyingq 7y agoYou can do it in SQL, but it's not simple. Something like: WITH stuff AS ( SELECT bday, carcolor, ROW_NUMBER() OVER ( PARTITION BY bday,carcolor ORDER BY bday,carcolor ) rownum FROM friends ) SELECT * FROM stuff WHERE rownum > 1;
- colonwqbang 7y agoYou could write this as a simple join too, right? At least assuming the friends table has a primary key. select f1.id, f2.id from friends f1, friends f2 where f1.bday = f2.bday and f1.carcolor = f2.carcolor and f1.id > f2.id;
- deleted 7y ago[deleted]
- okusername 7y agoBoth of you are missing the point. Once you normalize, car color would be an attribute on the car table, and to map those you need many-to-many lookup tables. It can be done obviously, but it's more effort to do, maintain and update. Depending on your requirements, graph db like features can provide an easier abstraction.
- taeric 7y agoThis feels like a straw man. Don't normalize if it causes pain. Similarly, don't expect that a single data model will suffice for all needs in an application. Expect to have to maintain anything that is useful.
- okusername 7y agoObviously, if you put all data into one table, it's not a complex query. (But then you also just reinvented document databases with its own set of problems.) Even having them in several tables is not rocket science, OP was just trying to give an easy example of types of queries that are easier with datomic than with sql.
- taeric 7y agoMy point is that data has to be maintained in whatever forms you are keeping it in. Often with different requirements on why it is there. Yes, this is a large part of why we use databases. They will do most of this heavy lifting. However, I don't think it changes the game. If you want some access to be easy or quick, you have to maintain the data in that format.
- okusername 7y agoNo, you're completely wrong. Graph databases, document databases, K/V stores and so on have completely different models, guarantees and performance characteristics than relational databases.
- taeric 7y agoThat is restating my point. Different data stores have different characteristics. Identify which ones you care about and make the tradeoffs required. They all require effort. And it is not uncommon to want your data available in different ways at different times.
- jmiskovic 7y agoIt's possible in SQL, in Datascript it's effortless. There's a big difference in mental overhead and thus how often you would want reach into DB. There are other benefits. You don't do any string mungling, your query is itself composed of data structures. You can build it easily with code, so your queries become as elaborate as you can generate them. Unlike SQL tables that you have to figure out from start, the data model is a collection of facts, with each fact consisting of {entity_id, attribute, value, transaction_info}. By adding facts to database you build the knowledge about entities and different relations between entities in an organic way. You can still use the table model, or you can use graph model. The whole DB is just a value in memory. You can transit it to server, store history copies in memory (for undo/redo), do diffs, whatever you need. As for monitoring changes, I'm using the Posh lib (also mentioned in article). It monitors the DB and re-renders react component if there are transactions relevant to component's queries. It seems very efficient so far, but I still have to test it with large number of components and transactions.
- amelius 7y ago> As for monitoring changes, I'm using the Posh lib (also mentioned in article). It monitors the DB and re-renders react component if there are transactions relevant to component's queries. It seems very efficient so far, but I still have to test it with large number of components and transactions. Interesting. Do you know if, upon a change, it reruns the queries from scratch, or does it update the results based on the actual changes?
- jmiskovic 7y agoIt will re-run the queries whenever new transactions contain new data for queried entities. It does so by pattern matching on transaction data. For truly reactive datalog subscriptions, let's see what happens with clj-3df project. Unlike Datascript, it requires you to use server infrastructure right from start.