mu

package module
v0.0.0-...-e82adf8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2017 License: MIT Imports: 12 Imported by: 2

README

mu

Warning: Here be dragons, and lots of them. mu is nowhere near finished, production ready or guaranteed (or even likely) to not mess up your data. It is part research project, part utility in use at (really) tiny scale. You're welcome to look around and have fun (and give feedback), but don't expect that it won't mess up things.

mu is a database that stores tuples, with a lightweight schema mechanism and a design that will support a powerful query language in the future.

It is inspired by Datomic and DataScript and follows Datomic's API closely.

mu is intended to be used in places where sqlite is used, but where a more flexible schema and (in the future) more powerful queries and/or immutable storage are desired.

Quickstart

Using mu currently means using its Go API. Here's a small example:

import (
    "fmt"
    "github.com/heyLu/mu"
)

func main() {
    conn, err := mu.Connect("file://posts.db")
    db, _ := conn.Db()

    iter := db.Eavt().Datoms()
    for datom := iter.Next(); datom != nil; datom = iter.Next() {
        fmt.Println(datom)
    }
}

For a more detailed example, take a look at the notes example application.

Documentation

For now, you need to be familar with both Go and Datomic to be able to use mu. In the future, we hope to provide a REST API for use with other languages, detailed documentation for both the Go API and the commandline interface.

Note that the following are not implemented right now. (Which may be considered as "the interesting parts" of Datomic.)

  • queries (in progress.)
  • pull api (planned.)
  • indexing (in progress. as of now, we can only read segmented indexes.)
  • proper schema support (in progress. attribute changes are currently not checked for correctness.)

Contributing

Thanks for your interest! Please take the following things into consideration:

  • all contributors are expected to follow our [Code of Conduct]
  • some areas for improvements:
    • compatibility with Datomics API
    • documentation and examples
    • extensive testing
    • performance

mu is currently distributed under the MIT license. By contributing to it you agree to license your contribution under the same license.

Thanks

First and foremost, a very big thank you to Rich Hickey and everyone who has worked on Datomic. This wouldn't be possible without you, thank you for envisioning and implementing a database that works in tandem with functional programming and immutable data structures.

In no particular order:

  • DataScript, which provides both inspiration and the BTSet implementation on which ours is based
  • Go and it's creators, which provides us with a deeply pragmatic language that's a joy to work with.

FAQ

  • Why? Both Datomic and DataScript could be used instead.

    mu is intended to be used in situations were neither Datomic nor DataScript are appropriate. In particular, Datomic has relatively high memory requirements, which make it unsuitable for commandline tools like the notes example. DataScript, on the other hand, is written in JavaScript and intended for use in web applications and does not support some Datomic features that we'd like to have, notably the reified schema and history.

  • When should I use it?

    First of all, if you're already happy with Datomic and/or DataScript, you shouldn't. mu is not intended to replace them.

    However, if you are in a situation where you would want to use something like sqlite, but want "more" (indexes, flexible schema, api, history, and in the future, powerful queries), then you might want to have a closer look.

    For now, you don't want to use it with large data sets, or anything non-experimental. In general, it is usable in "personal scale" projects.

  • Why is it written in Go?

    There is no definitive reason for that, but it surely helped that it compiles fast, supports standalone binaries and allows for use in commandline and other short running applications. It also helped that I was already familar with it and have recently written a few smallish applications in it.

    Alternative languages I've considered using are Rust and Ocaml, but I'm not familar to use either of those while also figuring out how to write mu itself. Aside from that, the main benefit would be to support access to the API from C via a FFI interface.

Documentation

Overview

Package mu provides the user-facing api for the mu database.

Index

Constants

View Source
const (
	DbIdent          = 10 // :db/ident
	DbCardinality    = 41 // :db/cardinality
	DbCardinalityOne = 35 // :db.cardinality/one
	DbType           = 40 // :db/valueType
	DbTypeString     = 23 // :db.type/string
	DbPartDb         = 0  // :db.part/db
	DbPartTx         = 3  // :db.part/tx
	DbPartUser       = 4  // :db.part/user
)

Variables

This section is empty.

Functions

func A

func A(attribute database.Keyword) pattern.Pattern

func Ae

func Ae(attribute database.Keyword, entity database.HasLookup) pattern.Pattern

func Aev

func Aev(attribute database.Keyword, entity database.HasLookup, value interface{}) pattern.Pattern

func Attribute

func Attribute(namespace, name string) database.Keyword

func Connect

func Connect(rawUrl string) (connection.Connection, error)

Connect connects to the database specified at the location given by the url.

The following formats are supported:

  • memory://<path>?name=<name> Connects to an in-memory database with the given name.
  • files://<path-to-dir>?name=<name> Connects to an on-disk database in the directory with the given name. A single directory may contain multiple databases with different names.
  • file://<path-to-file> Connects to a single-file database. This database will not support the future history api, only the log.
  • backup://<path-to-backup>[?root=<t>] Connects to a datomic backup, with an optional root if the directory contains multiple backups.

func CreateDatabase

func CreateDatabase(rawUrl string) (bool, error)

CreateDatabase creates a new database at the location given by the url.

It returns true if a new database was created and false if it already existed.

func Datoms

func Datoms(db *database.Db, p pattern.Pattern) (index.Iterator, error)

Datoms returns an iterator matching the given pattern.

func DatomsString

func DatomsString(db *database.Db, patternEDN string) (index.Iterator, error)

DatomsString parses a pattern from the string and returns an iterator.

The pattern must be a string in EDN format of the form [e a v], where e, a and v may be variables or values.

See Datoms for details.

func Datums

func Datums(datoms ...transactor.TxDatum) []transactor.TxDatum

func E

func Ea

func Ea(entity database.HasLookup, attribute database.Keyword) pattern.Pattern

func Eav

func Eav(entity database.HasLookup, attribute database.Keyword, value interface{}) pattern.Pattern

func Id

func Id(id int) database.Id

func Keyword

func Keyword(namespace, name string) database.Keyword

func LookupRef

func LookupRef(attribute database.Keyword, value interface{}) database.LookupRef

func NewDatom

func NewDatom(entity int, attribute int, value interface{}) index.Datom

func NewDatum

func NewDatum(entity database.HasLookup, attribute database.HasLookup, value interface{}) transactor.Datum

func NewDatumRaw

func NewDatumRaw(entity int, attribute int, value interface{}) transactor.Datum

func Part

func Part(id int) int

Part returns the partition id of the given entity id.

func PartEnd

func PartEnd(part int) int

func PartStart

func PartStart(part int) int

func Q

func Q(q interface{}, inputs ...interface{}) (map[query.Indexed]bool, error)

func QString

func QString(queryEDN string, inputs ...interface{}) (map[query.Indexed]bool, error)

func Retraction

func Retraction(datom index.Datom) transactor.Datum

func Tempid

func Tempid(part, id int) int

Tempid creates a temporary id in the given partition for use in a transaction.

func Transact

func Transact(conn connection.Connection, txData []transactor.TxDatum) (*transactor.TxResult, error)

Transact adds the datoms given by the txData to the connection.

The result contains a reference to the database before and after the transaction, the datoms that were transacted and a map from tempids to the assigned ids.

func TransactString

func TransactString(conn connection.Connection, txDataEDN string) (*transactor.TxResult, error)

TransactString adds the datoms given by the txData to the connection.

The txData is given as EDN data, which is parsed and converted to the format accepted by Transact.

Apart from the different input, the behavior is the same as that of Transact.

func With

func With(db *database.Db, txData []transactor.TxDatum) (*database.Db, error)

With returns a database with the txData added as if it were transacted.

Types

This section is empty.

Directories

Path Synopsis
cmd
mu command
notes command
parser command
collection
btset
Package btset implements an immutable B+-tree.
Package btset implements an immutable B+-tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL