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

ovee-db

v0.0.6

Published

Simple CRUD access to a database

Downloads

10

Readme

Ovee DB

A very simple wrapper around the Node MongoDB Driver to facilitate easy CRUD operations.

Installation

Just run a npm install --save ovee-db.

Usage

Here's a simple example of how to use Ovee DB:

const OveeDB = require('../dist').OveeDB;

(async () => {
    let db;
    try {
        db = new OveeDB('mongodb://localhost:27017/ovee', 'ovee');

        let car1 = await db.create('cars', {
            name: 'Ford Mustang'
        });

        const car2 = await db.create('cars', {
            name: 'Chevrolet Corvette'
        });

        let cars = await db.list('cars');
        console.log(cars);

        car1.name = 'New Model of Ford Mustang';
        car1 = await db.update('cars', car1);

        cars = await db.list('cars');
        console.log(cars);

        for (let car of cars) {
            await db.delete('cars', car);
        }

    } catch (err) {
        console.error(err);
    } finally {
        if (db != null) {
            await db.disconnect();
        }
    }

})();

Collections

Just like MongoDB, Ovee DB organizes objects in collections within a database. Every Ovee DB call therefore has a collection parameter.

IDs

All objects are identified by their Mongo IDs (field _id).

When creating a new object in the database, the object is automatically assigned an _id. For any further operations with this object (updating it, deleting it), make sure it still has its _id property set.

When retrieving an object using OveeDB.get use the _id to identify the given object.

Initializing Ovee DB

To initialize a new database connection, construct a new OveeDB object:

const db = new OveeDB(private mongoUri: string,
                private dbName: string,
                private mongoOptions: MongoClientOptions | null = null): OveeDB
                

On creation, no database connection will be opened yet. The database will be connected to once the first actual transaction happens.

Creating a new object

To create a new object in the DB, use OveeDB.create:

create(collection: string, object: any): Promise<any>;
  • collection: The collection name in which the object should be crated (e.g. 'cars').
  • object: The object to be created
  • Returns a Promise that resolves to the newly created object (already containing its _id property).

Updating an existing object

To update an existing object, pass it to OveeDB.update. Make sure it contains its _id property.

update(collection: string, object: any): Promise<any>
  • collection: The collection name in which the object should be updated.
  • object: The new version of the object, containing an _id property.
  • Returns a Promise that resolves to the updated object.

Retrieve an object

To retrieve an existing object, identified by its _id property, use OveeDB.get:

get(collection: string, _id: string): Promise<any>
  • collection: The collection name to retrieve the object from
  • _id: The identifier of the object to be retrieved
  • Returns a Promise that resolves to either the retrieve object (if one was found) or resolves without a result if no object was found.

List objects

To list all objects in a collection, or to list all objects matching certain criteria, use OveeDB.list:

list(collection: string, criteria: any = {}): Promise<any[]>
  • collection: The collection name to list objects from
  • criteria: If left empty, all objects in the collection will be retrieved. If set, should contain an object where each property is a filter for object properties. E.g. passing {name: 'Chevrolet Corvette'}', only returns objects whose name is 'Chevrolet Corvette'.

Disconnecting from the database

To disconnect from the database, use OveeDB.disconnect:

    disconnect(): Promise<any> {
  • Returns a Promise that resolves when the disconnect happened.