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

nomatic-data

v4.2.3

Published

Extensible Object-relational Mapper for Node.js

Downloads

24

Readme

nomatic-data

Greenkeeper badge Semantic Release GitHub release npm Build Status Coverage Status Known Vulnerabilities dependencies Status devDependencies Status License Join the chat at https://gitter.im/nomatic-data/Lobby

Extensible Object-relational Mapping Framework for Node.js

Overview

Written in TypeScript, this package uses Active Record, Data Mapper, and Adapter patterns to create an Object-Relational Mapping (ORM) tool that provides flexibility and extensibility.

Adapters allow you to connect to a variety of data sources. You can use a pre-built Adapter (see table below), or you can write your own by implementing either the Adapter or DatabaseAdapter abstract classes.

Each Adapter is operated by one or more Mapper instances. Each Mapper instance is managed by a Container instance. A Mapper will generate Record instances, which store the state of each document in the collection.

Installation

You can install from npm by doing:

npm i --save nomatic-data

If you want to write your own adapter, you can stop there. Otherwise, you'll need to install an adapter:

| Adapter | Author | Links | Installation | | :--- | :--- | :--- | :--- | | ArangoDB | bdfoster | npm, GitHub | npm i --save nomatic-arangodb-adapter |

Example

This example uses the ArangoDB adapter.

import { Container } from 'nomatic-data';
import ArangoDBAdapter from 'nomatic-arangodb-adapter';

const adapter = new ArangoDBAdapter({
    name: 'my-database',
    host: '127.0.0.1',
    port: 8579,
    password: 'somethingMoreSecureThanThis'
});

const store = new Container({
    adapter: adapter,
    
    /**
     * A few hooks are provided for your convenience, including:
     * - beforeGet
     * - afterGet
     * - beforeInsert
     * - afterInsert
     * - beforeUpdate
     * - afterUpdate
     * - beforeValidate
     * - afterValidate
     */ 
    beforeInsert(mapper, record) {
        record.createdAt = new Date();
    },
    beforeUpdate(mapper, record) {
        record.updatedAt = new Date();
    },
    
    /**
     * Here, we define the schema of all of our mappers. Other options
     * for each mapper can also be set here. Schema validation is provided
     * by [ajv](https://github.com/epoberezkin/ajv).
     */
    mappers: {
        people: {
            properties: {
                /**
                 * Implicit properties, such as `id` and `rev`, need not be 
                 * defined here. 
                 */ 
                firstName: {
                    type: 'string'
                },
                lastName: {
                    type: 'string'
                },
                emailAddress: {
                    type: 'string',
                    format: 'email'
                }
            },
            required: ['firstName', 'lastName'],
            /**
             * By default, additional properties are allowed in the record.
             */
            additionalProperties: false
        },
        accounts: {
            properties: {
                people: {
                    type: 'array',
                    items: {
                        type: 'string',
                        /**
                         * The 'mapper' keyword enforces relational integrity. Each item
                         * in this array matches an `id` of a record in the collection
                         * managed by the 'people' mapper.
                         */ 
                        mapper: 'people'
                    },
                    default: []
                }
            }
        }
    }
});

/**
 * The `load()` method will establish a connection with the database server, 
 * ensure that the database exists (or it will try and create it), and 
 * ensure all collection exists (or will create them).
 */
store.load().then(() => {
    return store.insertAll('people', [
        { firstName: 'John', lastName: 'Doe' },
        { firstName: 'Jane', lastName: 'Doe' }
    ]);
}).then(() => {
    /**
     * This is one way you can query for documents.
     */
    store.find('people')
        .where('lastName')
        .eq('Doe')
        .sort('firstName', 1)
        .limit(2)
        .skip(1)
        .run().then((results) => {
        //...
    });
    
    /**
     * You can also query much like how MongoDB query filters. The supported operators are:
     *  - $and
     *      Syntax: { $where: { $and: [ <expression>, ..., <expression> }, ... }
     *  - $or
     *      Syntax: { $where: { $or: [ <expression>, ..., <expression> }, ... }
     *  - $eq (expression)
     *      Syntax: { <property>: { $eq: { <value> } }
     *  - $ne (expression)
     *      Syntax: { <property>: { $ne: { <value> } }
     *  - $gt (expression)
     *      Syntax: { <property>: { $gt: { <value> } }
     *  - $gte (expression)
     *      Syntax: { <property>: { $gte: { <value> } }
     *  - $lt (expression)
     *      Syntax: { <property>: { $lt: { <value> } }
     *  - $lte (expression)
     *      Syntax: { <property>: { $lte: { <value> } }
     *  - $in (expression)
     *      Syntax: { <property>: { $in: [ <value>, ..., <value> ] }
     *  - $nin (expression)
     *      Syntax: { <property>: { $nin: [ <value>, ..., <value> ] }
     *  - $exists (expression)
     *      Syntax: { <property>: { $exists: <true | false> } }
     * 
     * An expression always follows this form: 
     *  { <property>: { <operator>: <value> | [ <value>, ..., <value>] }
     *  
     * All the operators above can only be used in a $where object. 
     */
    store.findAll('people', {
        $where: {
            firstName: 'Jane'
        },
        $sort: [
            ['firstName', 1]
        ],
        $limit: 2,
        $skip: 1
    }).then((results) => {
        //...
    });
});

The API documentation (generated by TypeDoc) can be found here.

More documentation will be added as moves forward, but if you have a question please feel free to open an issue.