0.0.13 • Published 1 year ago

@shieldsbetter/sb-optimistic-entities v0.0.13

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

sb-optimistic-entities

Optimistic locking library for MongoDb. Perform updates with plain Javascript.

TL;DR

const assert = require('assert');
const OptEntCollection = require('@shieldsbetter/sb-optimistic-entities');
const { MongoClient } = require('mongodb');

async main() {
    const dbClient = await MongoClient
            .connect(process.env.MONGOD_URI)
            .then(mc => mc.db('TestDb'));
    const petsCollection = new OptEntCollection(dbClient.collection('Pets'));

    await petsCollection.insertOne({
        _id: 'Ellie',
        breed: 'Azawakh',
        age: 6
    });

    // If there is a conflicting update, this will retry automatically
    // with the new value.
    await petsCollection.updateOne({ _id: 'Ellie' }, ellie => {
        ellie.age++;
        return ellie;
    });

    const entity = await petsCollection.findOne({ _id: 'Ellie' });
    assert.deepEqual(entity, {
        _id: 'Ellie',
        breed: 'Azawakh',
        age: 7;
    });
}
0.0.13

1 year ago

0.0.10

2 years ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago