An embedded relational datalog storage engine inspired by Datomic and DataScript. This is a fork of [Mozilla's unmaintained project by the same name](https://github.com/mozilla/mentat).
Go to file
Nick Alexander dcd9bcb1ce Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341)
* Pre: Drop unneeded tx0 from search results.

* Pre: Don't require a schema in some of the DB code.

The idea is to separate the transaction applying code, which is
schema-aware, from the concrete storage code, which is just concerned
with getting bits onto disk.

* Pre: Only reference Schema, not DB, in debug module.

This is part of a larger separation of the volatile PartitionMap,
which is modified every transaction, from the stable Schema, which is
infrequently modified.

* Pre: Fix indentation.

* Extract part of DB to new SchemaTypeChecking trait.

* Extract part of DB to new PartitionMapping trait.

* Pre: Don't expect :db.part/tx partition to advance when tx fails.

This fails right now, because we allocate tx IDs even when we shouldn't.

* Sketch a db interface without DB.

* Add ValueParseError; use error-chain in tx-parser.

This can be simplified when
https://github.com/Marwes/combine/issues/86 makes it to a published
release, but this unblocks us for now.  This converts the `combine`
error type `ParseError<&'a [edn::Value]>` to a type with owned
`Vec<edn::Value>` collections, re-using `edn::Value::Vector` for
making them `Display`.

* Pre: Accept Borrow<Schema> instead of just &Schema in debug module.

This makes it easy to use Rc<Schema> or Arc<Schema> without inserting
&* sigils throughout the code.

* Use error-chain in query-parser.

There are a few things to point out here:

- the fine grained error types have been flattened into one crate-wide
  error type; it's pretty easy to regain the granularity as needed.

- edn::ParseError is automatically lifted to
  mentat_query_parser::errors::Error;

- we use mentat_parser_utils::ValueParser to maintain parsing error
  information from `combine`.

* Patch up top-level.

* Review comment: Only `borrow()` once.
2017-02-24 15:33:48 -08:00
build Ensure minimum rustc version in a build script. r=nalexander (#326) 2017-02-17 12:04:45 -08:00
core Mark every project as being part of the workspace. r=nalexander 2017-02-20 11:04:08 -08:00
db Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
edn Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
fixtures Add test databases. 2017-01-10 12:09:00 -08:00
parser-utils Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
query Pre: fix query/Cargo.toml indenting. 2017-02-23 18:31:57 -08:00
query-algebrizer Expand query algebrizer. r=nalexander 2017-02-23 18:39:49 -08:00
query-parser Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
query-translator Implement query-translator. (#301) r=nalexander 2017-02-23 18:39:49 -08:00
sql Support accumulating TypedValue instances into a SQL query. (#339) r=nalexander 2017-02-23 18:39:43 -08:00
src Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
tests Run cargo fmt. r=me 2017-01-10 10:54:37 -08:00
tx Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
tx-parser Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
.gitignore Rudimentary printing of EDN values. (#209) r=jsantell 2017-01-28 14:18:17 -08:00
.travis.yml Simplify .travis.yml to use cargo test --all. 2017-02-20 11:04:18 -08:00
Cargo.toml Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341) 2017-02-24 15:33:48 -08:00
CONTRIBUTING.md More Rust notes. 2017-02-21 10:45:21 -08:00
LICENSE Change license to Apache. Fixes #74. 2016-11-22 11:40:37 -08:00
README.md Move the bin to src and take on clap dependency for command line arg parsing. Fixes #150. r=rnewman 2017-01-10 10:53:34 -08:00

Project Mentat

Project Mentat is a persistent, embedded knowledge base. It draws heavily on DataScript and Datomic.

The first version of Project Mentat, named Datomish, was written in ClojureScript, targeting both Node (on top of promise_sqlite) and Firefox (on top of Sqlite.jsm). It also works in pure Clojure on the JVM on top of jdbc-sqlite. The name was changed to avoid confusion with Datomic.

This branch is for rewriting Mentat in Rust, giving us a smaller compiled output, better performance, more type safety, better tooling, and easier deployment into Firefox and mobile platforms.

Motivation

Mentat is intended to be a flexible relational (not key-value, not document-oriented) store that doesn't leak its storage schema to users, and doesn't make it hard to grow its domain schema and run arbitrary queries.

Our short-term goal is to build a system that, as the basis for a User Agent Service, can support multiple Tofino UX experiments without having a storage engineer do significant data migration, schema work, or revving of special-purpose endpoints.

By abstracting away the storage schema, and by exposing change listeners outside the database (not via triggers), we hope to allow both the data store itself and embedding applications to use better architectures, meeting performance goals in a way that allows future evolution.

Comparison to DataScript

DataScript asks the question: "What if creating a database would be as cheap as creating a Hashmap?"

Mentat is not interested in that. Instead, it's strongly interested in persistence and performance, with very little interest in immutable databases/databases as values or throwaway use.

One might say that Mentat's question is: "What if an SQLite database could store arbitrary relations, for arbitrary consumers, without them having to coordinate an up-front storage-level schema?"

(Note that domain-level schemas are very valuable.)

Another possible question would be: "What if we could bake some of the concepts of CQRS and event sourcing into a persistent relational store, such that the transaction log itself were of value to queries?"

Some thought has been given to how databases as values — long-term references to a snapshot of the store at an instant in time — could work in this model. It's not impossible; it simply has different performance characteristics.

Just like DataScript, Mentat speaks Datalog for querying and takes additions and retractions as input to a transaction. Unlike DataScript, Mentat's API is asynchronous.

Unlike DataScript, Mentat exposes free-text indexing, thanks to SQLite.

Comparison to Datomic

Datomic is a server-side, enterprise-grade data storage system. Datomic has a beautiful conceptual model. It's intended to be backed by a storage cluster, in which it keeps index chunks forever. Index chunks are replicated to peers, allowing it to run queries at the edges. Writes are serialized through a transactor.

Many of these design decisions are inapplicable to deployed desktop software; indeed, the use of multiple JVM processes makes Datomic's use in a small desktop app, or a mobile device, prohibitive.

Mentat is designed for embedding, initially in an Electron app (Tofino). It is less concerned with exposing consistent database states outside transaction boundaries, because that's less important here, and dropping some of these requirements allows us to leverage SQLite itself.

Comparison to SQLite

SQLite is a traditional SQL database in most respects: schemas conflate semantic, structural, and datatype concerns; the main interface with the database is human-first textual queries; sparse and graph-structured data are 'unnatural', if not always inefficient; experimenting with and evolving data models are error-prone and complicated activities; and so on.

Mentat aims to offer many of the advantages of SQLite — single-file use, embeddability, and good performance — while building a more relaxed and expressive data model on top.

Contributing

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

See CONTRIBUTING.md for further notes.

This project is very new, so we'll probably revise these guidelines. Please comment on an issue before putting significant effort in if you'd like to contribute.

Building

Right now this code is located on a branch, so you first need to git checkout rust. To build and test the project, we are using Cargo.

To build all of the crates in the project use:

cargo build

To run tests use:

# Run tests for the core code (src/)
cargo test

# Run tests for the query-parser folder
cargo test -p mentat_query_parser

To start the server use:

cargo run serve

To pass in custom arguments to the cli through Cargo, you'll need to pass -- after the command to ensure they get passed properly. For example:

cargo run serve -- --help

For most cargo commands you can pass the -p argument to run the command just on that package. So, cargo build -p mentat_query_parser will build just the "query-parser" folder.

License

Project Mentat is currently licensed under the Apache License v2.0. See the LICENSE file for details.

SQLite dependencies

Mentat uses partial indices, which are available in SQLite 3.8.0 and higher.

It also uses FTS4, which is a compile time option.