Crate datom[][src]

Expand description

An open-source database inspired by Datomic.

// SPDX-FileCopyrightText: 2021 Lutris Engineering, Inc
// SPDX-License-Identifier: BlueOak-1.0.0 OR BSD-2-Clause-Patent
// SPDX-FileContributor: Piper McCorkle <piper@lutris.engineering>

Currently built on top of sled, a modern embedded database, and is only suitable for embedded usage. Future multi-peer support is planned.

If you aren’t already familiar with Datomic, it might help to look over Datomic’s excellent documentation. To the user, datom-rs functions extremely similarly to Datomic.

use datom::{backends::SledStorage, Connection, EntityResult, Transaction, Value, ID};

// Use the sled storage backend to create a temporary database
let storage = SledStorage::connect_temp()?;

// Create a connection from that backend
let conn = Connection::new(storage);

// Create an ID to use for the username attribute
let username = ID::new();
// Create an ID to use for the user's entity
let user = ID::new();

// Create a transaction setting the username attribute on the user
// entity to "pmc"
let mut tx = Transaction::new();
tx.add(user.into(), username.into(), "pmc".into());
// Execute the transaction using the connection
conn.transact(tx)?;

// Get a view of the database in the current point in time
let db = conn.db()?;
// Get the value of the username attribute on the user entity
if let EntityResult::Value(Value::String(u)) = db.entity(user.into())?.get(username.into())? {
    println!("The user's username is {}.", u);
}

Modules

Storage backends

IDs for the built-in attributes and other idents

Serialization/deserialization functions

API for storage backends

Structs

An iterator over attributes in a sled-backed database

An imperative way to generate an attribute’s schema

A persistent connection to a database

A view of a database at a specific point in time

A datom, or a single fact at a single point in time. Short for data atom.

An iterator over Datoms

An entity in a database

An entity ID

n sorted iterators, merged

A set of facts which can be transacted into a database connection

The record of a past transaction

The result of running a Transaction on a Connection

Enums

The type of an attribute’s values

Network/disk errors

Whether a datom is showing an addition or a retraction

An un-resolved entity ID, which can be used to resolve entities by ident or unique attribute

The result of getting an attribute on an entity

A fact which hasn’t yet been converted to a Datom (or set of Datoms)

The four indices used in the underlying data store. The names refer to the serialization order, and by extension the sort order.

Errors during a Database query

An error in the underlying storage backend

Errors during a Transaction

An attribute value.

Traits

A type which can be appended to a transaction

Functions

Create a new connection which uses a dynamically dispatched storage backend

Type Definitions

A connection which uses a dynamically dispatched storage backend