datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
2018-02-27T01:07:34.000273Z

datascript doesn't let you query old versions anyway, because it's all in memory

2018-02-27T01:08:44.000009Z

why can't you just transact new maps into entities as they become available?

2018-02-27T01:10:41.000096Z

could https://github.com/alandipert/intension help?

devn 2018-02-27T03:36:36.000064Z

@thedavidmeister the data is basically a dump of a couple database tables. right now, it is just a snapshot of the tables at a point in time. the difference between the current version and the previous version might include updated entities, and without just having the delta of updated and created entities, we'd need to look at every map and create-or-update, no?

2018-02-27T03:37:56.000166Z

if you have no sense of "identity" for each map

2018-02-27T03:38:02.000051Z

every list of maps is a new list

2018-02-27T03:38:19.000010Z

there is no meaningful concept of "update" πŸ˜•

devn 2018-02-27T03:38:25.000004Z

they have IDs πŸ™‚

2018-02-27T03:38:28.000192Z

ah cool

2018-02-27T03:38:38.000236Z

well then can you map the IDs to :db/id in datascript?

devn 2018-02-27T03:38:51.000233Z

i don't know why i didn't think of that

devn 2018-02-27T03:38:56.000024Z

but lol yes, i could

2018-02-27T03:38:58.000154Z

try it

devn 2018-02-27T03:39:06.000008Z

i was adding tempids to everything like a bozo

2018-02-27T03:39:33.000087Z

i mean, i don't know if datascript supports your ids

devn 2018-02-27T03:39:39.000194Z

they're ints

2018-02-27T03:39:41.000040Z

but if they're numbers i don't see why it wouldn't work

2018-02-27T03:39:43.000192Z

ints yeah

2018-02-27T03:40:00.000242Z

although it's probably technically not supported

devn 2018-02-27T03:40:03.000025Z

what about across different tables though? if one of them has a colliding ID

2018-02-27T03:40:23.000212Z

again...

devn 2018-02-27T03:40:29.000007Z

πŸ™‚ yeah

2018-02-27T03:40:32.000204Z

whatever your definition of identity is

2018-02-27T03:41:41.000134Z

if your definition of identity is the ID, and the IDs collide, then they are the same entity, by definition

devn 2018-02-27T03:42:59.000060Z

i suppose i could get clever and do something like use an offset for each table to prevent collision

devn 2018-02-27T03:44:04.000171Z

table 1: (- (:id {:id 1}) 10000) table 2: (- (:id {:id 1}) 20000)

devn 2018-02-27T03:44:06.000134Z

etc.

2018-02-27T03:44:10.000063Z

yeah

2018-02-27T03:44:21.000143Z

datascript does something like that internally to differentiate between eids and txn ids

2018-02-27T03:44:53.000224Z

but really, this is pretty contextual at this point

2018-02-27T03:45:03.000001Z

there's probably no perfect answer

devn 2018-02-27T03:45:08.000043Z

though i do have 100s of thousands of some of these maps, so it might need to be more clever than that

2018-02-27T03:45:28.000185Z

that should still be fine

devn 2018-02-27T03:45:35.000177Z

yes, basically im looking to try and fit a whole lot of batched data into a tight, queryable package

2018-02-27T03:45:36.000262Z

js max int is something like 10^15

2018-02-27T03:45:52.000121Z

can it be two different dbs?

devn 2018-02-27T03:46:13.000052Z

per table, or are you talking about splitting and querying across dbs?

devn 2018-02-27T03:46:33.000113Z

i will need to do joins occasionally across the imported data

2018-02-27T03:46:43.000062Z

this is getting to where i'm not 100% sure

2018-02-27T03:47:00.000071Z

i have a feeling it's possible to stick multiple dbs into a query

2018-02-27T03:47:03.000228Z

but i haven't done it

devn 2018-02-27T03:48:21.000202Z

yes, i knew this was possible in datomic

2018-02-27T03:48:24.000097Z

not sure if datascript follows that

devn 2018-02-27T03:48:29.000132Z

any thoughts on speeding up the import?

devn 2018-02-27T03:49:28.000175Z

right now im just doing a (d/with-db (d/empty-db) (concat stuff more-stuff)) in a background thread, and swapping the value

2018-02-27T03:49:50.000230Z

hmmm

2018-02-27T03:50:01.000024Z

so you're building a new db from scratch every time

devn 2018-02-27T03:50:19.000051Z

yes, and so i guess what you mentioned above would be worth trying.

2018-02-27T03:50:19.000052Z

why not just (transact! conn [...])

2018-02-27T03:50:38.000070Z

provided you have the db/id bit working, it should ignore anything that is the same

2018-02-27T03:50:56.000071Z

i have no idea which is faster

2018-02-27T03:51:05.000210Z

but transact! certainly seems more idiomatic

devn 2018-02-27T04:03:58.000169Z

finding out now πŸ™‚

devn 2018-02-27T04:05:26.000144Z

loading 150k maps takes ~42 seconds

devn 2018-02-27T04:05:45.000066Z

basically the same with d/db-with

2018-02-27T04:05:53.000116Z

it's probably doing similar things under the hood

2018-02-27T04:06:04.000228Z

what about incremental updates?

2018-02-27T04:06:11.000013Z

is it any faster than the initial load?

devn 2018-02-27T04:06:23.000045Z

i only added one record, but it didn't appear so no

2018-02-27T04:06:41.000150Z

it took 42 seconds to add 1 record?

devn 2018-02-27T04:07:19.000195Z

oh, no, what im saying is i had a collection, and i changed a record in it but left it's ID the same, and then ran transact! over the whole collection again

devn 2018-02-27T04:07:26.000073Z

its*

2018-02-27T04:07:50.000127Z

right

devn 2018-02-27T04:08:00.000113Z

i was curious to see if it'd be able to quickly tell it didn't need to do anything with most of the maps

2018-02-27T04:08:18.000027Z

i wonder how long it takes to compare those maps outside datascript

2018-02-27T04:08:34.000141Z

maybe you can do the comparison yourself and just transact the diff

devn 2018-02-27T04:08:47.000034Z

yeah

devn 2018-02-27T04:09:05.000133Z

i also wonder if the types on the value side of a map have anything to do with performance

2018-02-27T04:09:15.000066Z

like, clojure.set/difference or something

devn 2018-02-27T04:09:23.000003Z

like are instants more expensive?

2018-02-27T04:09:59.000105Z

maybe, i'd imagine iso8601 strings are faster to compare, but i don't know

devn 2018-02-27T04:13:56.000144Z

I can probably slim some of these maps down.

devn 2018-02-27T04:14:07.000134Z

I bet that would have some appreciable impact

2018-02-27T04:22:07.000088Z

yeah i mean, at some point you just run into the limits of comparing lots of data

devn 2018-02-27T06:32:40.000063Z

From the datascript tutorial in reading: > Datom has (-hash) and (-eqiv) methods overloaded so only [e a v] take part in comparisons. It helps to guarantee that each datom can be added to the database only once. Does this mean that a retracted datom cannot be added after retraction?

devn 2018-02-27T06:33:32.000217Z

Are retraction and excision synonymous?

devn 2018-02-27T06:35:09.000141Z

> When datom is removed from a DB, there’s no trace of it anywhere. Retracted means gone.

devn 2018-02-27T06:36:07.000178Z

That makes it sounds like excision and retraction are the same, but perhaps I’m just confused by the role of :added in light of the comment about e a v comparison operations.

2018-02-27T07:20:52.000256Z

datascript has no history

2018-02-27T07:21:21.000207Z

i think a lot of the datascript API is to line up with datomic API rather than achieve a specific goal for datascript itself

2018-02-27T07:21:54.000150Z

if you wanted to sync datascript with datomic via transaction reports you'd need :added i think

rauh 2018-02-27T07:27:47.000236Z

@devn There is also conn-from-datoms in case you want to manually import. It's pretty fast. I use it to bootstrap my DB on CLJS.

fellshard 2018-02-27T16:11:57.000454Z

Datomic maintains history; you could rewind and look at the database at a given time, meaning all datoms retracted between that previous time and now would be visible again. Retraction is basically adding new information: "This datom no longer holds true; it used to up 'til now, but now it does not." Excision is much more dangerous, because it removes any trace that the datom was ever there, both currently and historically. Datascript maintains no history, as thedavidmeister said, so it doesn't necessarily make that distinction