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

crudbox

v1.0.7

Published

all in one NPM module for CRUD operations

Downloads

13

Readme

Crudbox

Crudbox is a package designed to provide unified CRUD operations that can work on multiple NoSQL databases(MongoDB and Firestore). Crudbox supports Node.js.

Documentation

Crudbox 1.0.6 was released on April 26, 2023. You can find more details on Github repository.

Contributors

Pull requests are always welcome! Please base pull requests against the main branch.

Please provide your MongoDB and Firebase configuration under __test__/env directory with file name testMongoDBAtlasConfig.ts and testFirebaseConfig.ts and do not push it to the origin.

View all 400+ contributors.

Installation

First install Node.js. Then:

$ npm install crudbox

Importing

import {Bucket} from "crudbox/lib/src/Bucket/Bucket.js";

Overview

Initializing a Bucket

First, we need to define a Bucket, a wrapper for a single NoSQL databse, and initilize it. Either an instance of IMongoConfiguration or IFirestoreConfiguration can be used to initialize each NoSQL database.

MongoDB

const connectionURI: string = `[MongoDB connection URI]`;
// mongodb+srv://[USER/ORGANIZATION]:[PASSWORD]@[CLUSTER]/?[OPTIONS]
const mongoConfig: IMongoConfiguration = { uri: connectionURI, database: "[Database Name]" };
const mongoBucketConfig: BucketConfiguration = new MongoBucketConfiguration(mongoConfig);
const bucket: Bucket = new Bucket(mongoBucketConfig, "[Bucket Name]");

Firestore

const config: IFirestoreConfiguration = {
    apiKey: "...",
    authDomain: "...",
    projectId: "...",
    storageBucket: "...",
    messagingSenderId: "...",
    appId: "...",
    measurementId: "..."
};
const firebaseBucketConfig: BucketConfiguration = new FirestoreBucketConfiguration(config);
const bucket: Bucket = new Bucket(firebaseBucketConfig, "[Bucket Name]");

After creating an instance of Bucket using BucketConfiguration, the Bucket can be initilized with a method Bucket.initialize().

const db: AppDatabase = await bucket.initialize();

Registering a Collection

Once the Bucket is intialized, Collection with generic type T can be added or registered using Bucket.addCollection<T>(name: string) method. Here, Collection has the same task unit with CollectionReference<T> of Firestore and Collection<T> of MongoDB.

const usersCollection: MongoDbCollection<IUser> = db.collection<IUser>('users');

Operating CRUD

CRUD operation can be executed on a registered Collection<T>.

CREATE

createOne

const newDocument: T = {...}; 
const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.createOne<T>(newDocument);

createMany

const newDocument: T[] = [...]; 
const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.createMany<T>(newDocuments);

RREAD

readOneById

const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.readOneById<T>(id);

readManyById

const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.readManyById<T>(ids);

UPDATE

updateOneById

const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.updateOneById<T>(id, updatingDocument);

updateManyById

const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.updateManyById<T>(updatingDocuments);

DELETE

deleteOneById

const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.deleteOneById<T>(id);

deleteManyById

const collection: Collection<T> = bucket.addCollection<T>('[Collection Name]');
const result = await collection.deleteManyById<T>(ids);