2.1.0 • Published 3 years ago

tbnd-repp v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

⚡ zapmongo

A mongoose wrapper.

Features

  • ⚡ Lightning fast!
  • 😴 A bunch of helpful functions
  • ⌨ Written in TypeScript

How to use

Initiate DB

const { Database } = require('zapmongo');
// or
import { Database } from 'zapmongo';

const db = new Database({ mongoURI: 'my-super-secret-mongo-uri-here', schemas: [
    {
        name: 'hello',
        data: {
            name: String,
            location: String
        }
    }
] });
// this will create a db and will have a schema named hello with the data of name and location.

Load a schema

const Schema = await db.load('hello');

Update/create data

await Schema.update({ name: "hello" }, { location: "world!" });
// this will look for data with name of hello, if it finds it, it replcae it to "world!" - if not it'll create a new document defaulting to the second argument. Nerd terms for if the 2nd param contains the same key as the first param, the key in the 2nd param will be favoured / used.

Find data

await Schema.findOne({ name: 'hello' }); // would return the first instance it can find that has name as "world!"
await Schema.find({ name: 'hello' }); // returns all data that has name as "world!"

Delete

await Schema.delete({ name: 'hello' }); // would delete the first piece of data it finds that has name as 'world!'

API

update(searchData: object, updateData: object): PromiseDocument

findOne(searchData: object): PromiseDocument

leaderboard(sort: SortFunction): Promise[ArrayDocument]

delete(searchData: object): Promiseboolean

create(data: object): PromiseDocument

increment,decrement(search: object, key: string, value: number): PromiseDocument

push(search: object, key: string, value: any): PromiseDocument