DEV Community

Cover image for Meet Reaves
Adriano Di Giovanni
Adriano Di Giovanni

Posted on

Meet Reaves

Reaves is a package that I've just released on npm. It is a Javascript implementation of the Entity-Attribute-Value model and the event sourcing pattern. It runs on Node.js. It is backed by Redis.

Simply put, Reaves lets you save and retrieve present and past string values for attributes that belong to entities identified by string IDs.

This very first release is pretty minimalistic. Nonetheless, Reaves already supports case-sensitivity, nullable and unique constraints for values and it implements a bunch of useful methods to query the data.

const { createEntityAttribute, CASE_SENSITIVE, NULLABLE, UNIQUE } = require('reaves')
const { generate } = require('randomstring')
const redis = require('redis')
const uuidv4 = require('uuid/v4')

const client = redis.createClient()
const entityName = 'player'
const attributeName = 'nickname'
const flags = CASE_SENSITIVE | NULLABLE | UNIQUE

createEntityAttribute(client, entityName, attributeName, flags, (err, playerNickname) => {
    if (err) {
        throw err
    }

    const entityId = uuidv4()
    const newValue = generate()
    const createdAt = Date.now()

    playerNickname.insert(entityId, newValue, createdAt, console.log.bind(console))
})

I'm very proud of Reaves because it is a not-so-small piece of software that solves a real problem. It solves it well, I think, and it doesn't require us - you and me - to add another technology to our stack.

The core functions are written in Lua for performance and atomicity. They are loaded into the script cache of Redis at runtime using another npm package of mine, luaload, that also concatenates multiple script files into one on-the-fly.

I'm going to use Reaves to implement some features that rely on past and present values of entity attributes for production or administration purposes.

And by the way, Reaves is the acronym of Redis entity attribute value event sourcing.

What do you think of Reaves and the idea behind it? Do you spot any drawbacks?

Please, let me know. It is the reason I wanted to share Reaves with you.

Thanks.

Top comments (0)