npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dynamodel-client

v0.2.4

Published

Amazon's DynamoDB client to manage multiple models per table.

Downloads

21

Readme

Dynamodel-client

NPM version NPM downloads Coverage Status

// TODO IN PROGRESS Dynamodel est une surcouche à DynamoDB, plus précisément de son client AWS.DynamoDB.DocumentClient. Il permet d'effectuer les mêmes opérations que sur DocumentClient mais avec un meilleur contrôle sur la rédaction des requêtes ainsi que sur le contrôle des données, aussi bien en lecture qu'en écriture.

Client

const dbClient = new Dynamodel(new AWS.DynamoDB.DocumentClient());
const dbClient = new Dynamodel(new AWS.DynamoDB.DocumentClient(), 'tablePrefix');

Schema

Les schéma décrivent les objets de la base de données.
Il est possible d'en créer deux types par défaut,
les Schema qui vont s'appliquer strictement aux objets et
les Schemaless qui ne vont contrôler que les attributs décrit dans le schéma, tout autre attribut pourra être écrit en base de données.

Schema example:

const fooSchema = new Schema({
    hashKey: {
        test: (value) => typeof value === 'number'
    },
    sortKey: {
        test: (value) => typeof value === 'string' && value.startWith('foo#');
    },
    attr1: {
        test: (value) => typeof value === 'string'
    },
    attr2: {
        test: (value) => value == undefined || typeof value === 'object'
    }
});

Schemaless example:

const barSchema = new Schemaless({
    hashKey: {
        test: (value) => typeof value === 'number'
    },
    sortKey: {
        test: (value) => value === 'bar'
    }
});

Model

Modélisation des schéma pour manipuler les éléments de la base de données avec l'ajout de fonctions.

const FooModel = model(barSchema);
FooModel.prototype.sortKey = 'foo';
class BarModel extends model(barSchema) {

    get sortKey() {
        return 'bar';
    }

    set sortKey(v) {
        /* read only */
    }
}

Advanced usage:

class BazModel extends model(barSchema) {

    private static readonly PREFIX = 'bar#';

    private _sortKey: string;
    private _subkey: string;

    get sortKey() {
        return this._sortKey;
    }

    set sortKey(value) {
        this._sortKey = value;
        this._subKey = value.substring(FooModel.PREFIX.length);
    }

    get subKey() {
        return this._subKey;
    }

    set subKey(value) {
        this._sortKey = FooModel.PREFIX + value;
        this._subKey = value;
    }
}

Table

Décrit une table et enregistre les différents modèles. Chaque modèle doit avec un schéma déterministe au niveau de sa clé primaire pour permettre d'appliquer le bon schéma lors des requêtes.

const myTable = new Table({
    name: 'myTable',
    primaryKey: {
        hash: 'hashKey',
        sort: 'sortKey'
    },
    indexes: {
        'sort-index': {
            hash: 'sortKey'
        }
    },
    models: [
        FooModel,
        BarModel
    ],
    modelKey: {
        path: 'modelKeyPath'
    }
});

modelKey (optionnel) permet d'identifier le bon modèle à l'aide d'un attribut supplémentaire (ex: les modèles d'une table sont différenciés par un autre attribut que ceux de la clé primaire).

Requests

Liste des opérations du client.

BatchDelete

Supprime un ensemble d'éléments d'une table depuis leurs clés primaire.

const response = await dbClient.batchDelete({
    table: myTable,
    keys: [
        new FooModel({ hashKey: 1 }),
        new BarModel({ hashKey: 1 })
    ]
});

BatchGet

Récupère un ensemle d'éléments d'une table depuis leurs clés primaire.

const response = await dbClient.batchGet({
    table: myTable,
    keys: [
        new FooModel({ hashKey: 1 }),
        new BarModel({ hashKey: 1 })
    ]
});

BatchPut

Ecrit un ensemble d'éléments d'une table depuis leurs clés primaire.

const response = await dbClient.batchPut({
    table: myTable,
    items: [
        new FooModel({ hashKey: 1, attr1: false, attr2: 'my value' }),
        new BarModel({ hashKey: 1, value: { a: true } })
    ]
});

Delete

const response = await dbClient.delete({
    table: myTable,
    key: new FooBar({ hashKey: 1 }),
    condition: attributeExists(path('attr1'))
});

Get

const response = await dbClient.get({
    table: myTable,
    key: new FooBar({ hashKey: 1 })
});

Put

const response = await dbClient.put({
    table: myTable,
    item: new FooBar({ hashKey: 1, attr1: true }),
    condition: and(
        attributeNotExists(hashKey()),
        attributeNotExists(sortKey())
    )
});

Query

const response = await dbClient.query({
    table: myTable,
    indexName: 'sort-index',
    keyCondition: equals(hashKey(), value('foo'))
});

Scan

const response = await dbClient.scan({
    table: myTable,
    select: 'COUNT'
});

Update item

const response = await dbClient.update({
    table: myTable,
    item: new FooModel({ hashKey: 1, attr1: false }),
    condition: and(
        attributeExists(hashKey()),
        attributeExists(sortKey())
    )
});

Update expression

const response = await dbClient.update({
    table: myTable,
    key: new FooModel({ hashKey: 1 }),
    updatable: new Updatable().set(path('attr1'), value(false)),
    condition: and(
        attributeExists(hashKey()),
        attributeExists(hashKey())
    )
});