All Projects → vvvvalvalval → Datomock

vvvvalvalval / Datomock

Licence: mit
Mocking and forking Datomic Peer connections in-memory.

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to Datomock

Spring Data Mock
Mock facility for Spring Data repositories
Stars: ✭ 110 (-9.09%)
Mutual labels:  database, mocking
Kakapo.js
🐦 Next generation mocking framework in Javascript
Stars: ✭ 535 (+342.15%)
Mutual labels:  database, mocking
Couchbase Lite Ios
Lightweight, embedded, syncable NoSQL database engine for iOS and MacOS apps.
Stars: ✭ 1,532 (+1166.12%)
Mutual labels:  database
Mytap
MySQL Unit Testing Suite
Stars: ✭ 118 (-2.48%)
Mutual labels:  database
Pkhex
Pokémon Save File Editor
Stars: ✭ 1,781 (+1371.9%)
Mutual labels:  database
Hackeronedb
The unofficial HackerOne disclosure Timeline
Stars: ✭ 117 (-3.31%)
Mutual labels:  database
Mysql Container
MySQL container images based on Red Hat Software Collections and intended for OpenShift and general usage. Users can choose between Red Hat Enterprise Linux, Fedora, and CentOS based images.
Stars: ✭ 117 (-3.31%)
Mutual labels:  database
Trivialdb
A simple database engine with common SQL queries support. Final project for course 'Introduction to Databases' of Tsinghua University, Fall 2018.
Stars: ✭ 114 (-5.79%)
Mutual labels:  database
Cmu 15 445
CMU的数据库系统课程
Stars: ✭ 120 (-0.83%)
Mutual labels:  database
R2dbc H2
R2DBC H2 Implementation
Stars: ✭ 118 (-2.48%)
Mutual labels:  database
Rust Etcd
An etcd client library for Rust.
Stars: ✭ 119 (-1.65%)
Mutual labels:  database
Cs notes
🚀自我小结
Stars: ✭ 118 (-2.48%)
Mutual labels:  database
Sqlite ecto2
Sqlite3 adapter for Ecto 2.2.x
Stars: ✭ 117 (-3.31%)
Mutual labels:  database
Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (+1260.33%)
Mutual labels:  mocking
Efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
Stars: ✭ 10,838 (+8857.02%)
Mutual labels:  database
Postgresql Ocaml
OCaml-bindings for the PostgreSQL database
Stars: ✭ 120 (-0.83%)
Mutual labels:  database
Bitnami Docker Mysql
Bitnami MySQL Docker Image
Stars: ✭ 116 (-4.13%)
Mutual labels:  database
Alpine Mariadb
MariaDB running on Alpine Linux [Docker]
Stars: ✭ 117 (-3.31%)
Mutual labels:  database
Databazel
The analytical and reporting solution for MongoDB
Stars: ✭ 118 (-2.48%)
Mutual labels:  database
Etherscamdb
Keep track of all current ethereum scams in a large database
Stars: ✭ 121 (+0%)
Mutual labels:  database

datomock

Mocking and forking Datomic connections in-memory.

Clojars Project

Notes:

  • This library is not an in-memory re-implementation of Datomic - just a thin wrapper on top of the Datomic Peer Library. All the heavy lifting is done by Datomic's 'speculative writes' (a.k.a db.with(tx)) and Clojure's managed references (atoms)
  • Only for Peers, not Clients.

Project maturity: beta quality. Note that you will probably not need to use this library in production.

Usage

(require '[datomic.api :as d])
(require '[datomock.core :as dm])

(def my-conn (d/connect "datomic:mem://hello-world"))

;; ... create a mock connection from a Database value:
(def starting-point-db (d/db my-conn))
(def mocked-conn (dm/mock-conn starting-point-db))

;; which is essentially the same as: 
(def mocked-conn (dm/fork-conn my-conn))

;; dm/fork-conn is likely what you'll use most.

Rationale and semantics

Mocked connections use Datomic's speculative writes (db.with()) and Clojure's managed references to emulate a Datomic connection locally.

The main benefit is the ability to 'fork' Datomic connections. More precisely, if conn1 is forked from conn2:

  • at the time of forking, conn1 and conn2 hold the same database value;
  • subsequent writes to conn1 will leave conn2 unaffected
  • subsequent writes to conn2 will leave conn1 unaffected

Because Datomic database values are persistent data structures, forking is extremely cheap in both space and time.

Applications

  • Write expressive tests: write tests as a tree of scenarios exploring various alternatives. In particular, this makes it very easy to write system-level tests that run fast. Forget about setup and teardown phases: they are respectively replaced by forking and garbage-collection.
  • Cheap, safe debugging: instantly reproduce your production environment on your local machine. Save and re-use as many checkpoints of your state as you need as you debug. Dry-run data patches and migrations safely before committing them to production.
  • Explore new database schemas: in particular, you can experiment with changes to your database schema without committing to them.
  • Staging environments / QA / CI: want one staging environment (Peer) for each pull-request on your app? Just have each of them use an in-memory fork of a shared database (or even your production database).
  • Ephemeral demos: want to let people experiment with your app without accumulating their manual changes? Just have them work on a fork, and discard it afterwards.
  • Ephemeral dev environments: similarly, it's usually better to always work on the same data when developing, and have the manual changes you've made while experimented be discarded at the end of the session.

Useful links:

How it works

Essentially, by putting a Datomic Database value in a Clojure Managed Reference (currently an Atom, may evolve to use an Agent instead) and using db.with() to update the state of that reference.

That's it, you now know how to re-implement Datomock yourself!

Actually, there are a few additional complications to make this work smoothly:

  • Log: the reference needs to hold not only a Database Value, but also a Log Value (for some strange reason, in Datomic, Log Values are not part of Database values).
  • Futures-based API: to match the interface of Datomic Connections, the library needs to provide a Futures-based API, which requires some additional work on top of Clojure references.
  • txReportQueue: the library needs to provide an implementation of that as well.

Mocked connections vs datomic:mem

How is this different than using Datomic memory databases, as in (d/connect "datomic:mem://my-db") ?

Mocked connections differ from Datomic's memory connections in several ways:

  • you create a memory connection from scratch, whereas you create a mocked connection from a starting-point database value
  • a mocked connection is not accessible via a global URI

Compatibility notes

This library requires Datomic 0.9.4470 or higher, in order to provide an implementation of the most recent methods of datomic.Connection.

However, if you need to work with a lower version, forking this library and removing the implementation of the syncSchema(), syncExcise() and syncIndex() should work just fine.

License

Copyright © 2016 Valentin Waeselynck and contributors.

Distributed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].