Datascript and Datomic tutorial book
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
SUMMARY.md add todo app Nov 2, 2016
add_data.md Update add_data.md May 12, 2016
advanced_queries.md
basic_queries.md
book.json
create_connection.md
create_database.md
create_schema.md
crud_apps.md
data_modeling.md
datalog_apps.md Create datalog_apps.md May 12, 2016
datalog_frameworks.md
datascript.md
datascript_architecture.md
datascript_getting_started.md Require statement fix. May 26, 2017
datascript_in_javascript.md
dato_framework.md
datomic.md
datomic_architecture.md
datomic_getting_started.md
entity-identity.md
javascript_api.md Update javascript_api.md May 12, 2016
javascript_integration.md
mori_integration.md
project_configuration.md
pull_data.md Update pull_data.md May 12, 2016
queries.md
retract_data.md
todo_app.md

README.md

Datascript

Datascript is based on the Datomic DB created by Cognitect.

Datalog

Datomic's query and rules system is an extended form of Datalog. Datalog is a deductive query system, typically consisting of:

  • A database of facts
  • A set of rules for deriving new facts from existing facts
  • A query processor that, given some partial specification of a fact or rule: finds all instances of that specification implied by the database and rules i.e. all the matching facts

Data model

The data model in Datascript/Datomic is based around atomic facts called datoms. A datom is a 4-tuple consisting of:

  • Entity ID
  • Attribute
  • Value
  • Transaction ID

Example:

[<e-id>  <attribute>      <value>          <tx-id>]
...
[ 167    :person/id       168373838          102  ]
[ 167    :person/name     "James Cameron"    102  ]
...
[ 234    :movie/id        173532083          102  ]
[ 234    :movie/title     "Die Hard"         103  ]
[ 234    :movie/year      1987               103  ]

The following query finds all entity-ids that have the attribute :person/namewith a value of "Ridley Scott":

[:find ?e
 :where
 [?e :person/name "Ridley Scott"]]

Useful resources

Learn datalog queries