[erlang-questions] BossDB - a sharded, caching, pooling, evented ORM for Erlang

Evan Miller <>
Mon Feb 20 21:48:12 CET 2012


BossDB is an advanced database ORM that was recently spun off from
Chicago Boss into its own project. If you hate parameterized modules,
parse transforms, and dirty compiler hacks, stop reading immediately,
because BossDB extensively (ab)uses all three in order to make
database work productive and fun.

GitHub page: https://github.com/evanmiller/boss_db

FEATURES

* Define your data model with parameterized modules. Accessor,
association, and save methods are automatically generated for you.
BossRecords, modeled on ActiveRecord, can be sent straight to ErlyDTL
for rendering (e.g. Person:name() in Erlang, or {{ person.name }} in
ErlyDTL).

* Validation and save hooks

* Five battle-tested database SQL/NoSQL adapters with test coverage:
Mnesia, MySQL, PostgreSQL, MongoDB, and Tokyo Tyrant.

* Easy to write additional adapters, just 200-300 lines of Erlang code

* Naming conventions similar to Rails (plural table names, -has,
-belongs_to, ...)

* Language-integrated querying. This goes a bit beyond parse
transforms and supports Unicode query operators directly inside Erlang
code -- 18 search operators in all.

* Intelligent, adapter-agnostic connection pooling

* Support for vertical sharding: model associations work across
independent databases.

* A model event system called BossNews, which can create notifications
based on custom rules (e.g. "execute this callback when this field
changes on this record")

* Memcached-based query and record caching. Cache entries are
automatically invalidation thanks to BossNews. Never write another
cache-related save hook again!


BossDB is certainly not for everybody, but with it you can write very
concise, readable code when dealing with a database in Erlang. BossDB
has been the centerpiece of Chicago Boss since 2009; it is a fairly
mature piece of software and being used in production on a number of
websites (including, I recently found out, the #1 dating website in
the Philippines). The best part IMHO is BossNews, which brings model
event notifications to the server with a simple API -- great for
creating alerts or real-time notifications.

It should be straightforward to integrate BossDB into existing stacks,
but note that you need to compile model files with the BossRecord
compiler. In addition, you will need to use the BossDB compiler chain
to take advantage of language-integrated queries (which involves an
unholy workflow of intercepting scanner errors, rewriting the token
list, running the tokens through a custom pre-processor[1], applying a
parse transform, and finally sending the transmogrified parse tree off
to compile:forms).

Future plans mainly involve adapting BossDB to work with other
databases; there is a half-finished Riak adapter included in the
project, but there is room for many more. BossDB should be able to
work with pretty much any SQL or NoSQL database that supports
querying.

Happy querying, and let me know if you have any questions about the project!

Best regards,

Evan



1. Aleppo, an alternative to EPP: https://github.com/evanmiller/aleppo



More information about the erlang-questions mailing list