Liking cljdoc? Tell your friends :D

quark.graph.normalization

An in-memory graph data store consisting of maps with links.

Introduction

This is a very basic database that stores entities. An entity is a Clojure map from attributes to values.

An attribute is a keyword, usually namespace-qualified.

An entity has exactly one unique identity attribute whose value acts as a globally-unique identifier for that entity. An entity may not have more than one unique identity attribute; if it does, the behavior is undefined.

A lookup ref is a vector pair of a unique identity attribute and a value, such as [:user/id 1234]. The combination of a unique identity attribute and its value uniquely identifies a single entity in the database.

Usage

Create a new database with new-db.

The schema of the database is the set of all unique identity attributes. add-id-attr extends the schema with a new unique identity attribute.

add inserts entities in the database. Entities already in the database are updated as by clojure.core/merge. (To replace an entity without merging, dissoc it first.)

All entites added to a database are automatically normalized: all nested entities are replaced with lookup refs to other entities in the database.

Entity normalization recognizes the following forms:

  • any non-entity value, including collections
  • a single entity
  • a collection (list, vector, set) of entities
  • a map where keys are any type, vals are single entities

Collection values may not mix entities and non-entities. Collections are searched only one layer deep: add will not recursively walk arbitrary data structures to search for entities to normalize.

Databases can be manipulated with primitive map operations such as get and dissoc. Keep in mind that there are no indexes: If you dissoc an entity from the database you may leave behind broken links to that entity.

To get nested maps back out, use pull, which follows a pull pattern to recursively expand entity lookup refs.

An in-memory graph data store consisting of maps with links.

## Introduction

This is a very basic database that stores entities. An *entity* is a
Clojure map from *attributes* to values.

An *attribute* is a keyword, usually namespace-qualified.

An entity has exactly one *unique identity* attribute whose value
acts as a globally-unique identifier for that entity. An entity may
not have more than one unique identity attribute; if it does, the
behavior is undefined.

A *lookup ref* is a vector pair of a unique identity attribute and a
value, such as `[:user/id 1234]`. The combination of a unique
identity attribute and its value uniquely identifies a single entity
in the database.

## Usage

Create a new database with `new-db`.

The schema of the database is the set of all unique identity
attributes. `add-id-attr` extends the schema with a new unique
identity attribute.

`add` inserts entities in the database. Entities already in the
database are updated as by `clojure.core/merge`. (To replace an
entity without merging, `dissoc` it first.)

All entites added to a database are automatically *normalized*: all
nested entities are replaced with lookup refs to other entities in
the database.

Entity normalization recognizes the following forms:

  - any non-entity value, including collections
  - a single entity
  - a collection (list, vector, set) of entities
  - a map where keys are any type, vals are single entities

Collection values may not mix entities and non-entities. Collections
are searched only one layer deep: `add` will not recursively walk
arbitrary data structures to search for entities to normalize.

Databases can be manipulated with primitive map operations such as
`get` and `dissoc`. Keep in mind that there are no indexes: If you
`dissoc` an entity from the database you may leave behind broken
links to that entity.

To get nested maps back out, use `pull`, which follows a pull
pattern to recursively expand entity lookup refs.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close