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

nosql-easy

v2.1.2

Published

This library aims to facilitate access to a non-relational database

Downloads

39

Readme

Installation

Install via NPM:

npm install nosql-easy

Database currently supported

  • Firebase - Firestore

Usage

.env (file)

#Firebase
FIRESTORE_CREDENTIAL={"credential":{"projectId":"your_project","clientEmail":"your_email","privateKey":"your_privateKey"}, "databaseURL":"your_url"}

#AWS
AWS_CREDENTIAL={"accessKeyId":"your_accessKeyId","secretAccessKey":"your_secretAccessKey","region":"sa-east-1"}

TypeScript

import { NoSqlEasy, NoSqlEasyConfig } from "nosql-easy";

NoSqlEasyConfig.setDialect("Firestore");

export class BaseService {
  public repository: NoSqlEasy;
  public collection: string;

  constructor(collection: string) {
    this.repository = new NoSqlEasy();
    this.collection = collection;
  }

  async insert(data: T): Promise<T> {
    return await this.repository.insert<T>(this.collection, data);
  }
}

Functionality

| Function | Description | Param | Return | | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | | insert<T, R = T> | Add a new document to this collection with the specified data, assigning it a document ID automatically. When the response class is informed, the return data will be transformed to it. | collection: string, data: T, ResponseClass?: new () => R | Promise<R> | | insertWithId<T, R = T> | Add a new document to this collection with the specified data, assigning it a document ID automatically, inserting a custom id. When the response class is informed, the return data will be transformed to it. | collection: string, data: T, ResponseClass?: new () => R | Promise<R> | | insertElementInArray | Add a new document to this collection with the specified data, and update fields into document referred | collection: string, id: string, arrayFieldName: string, Value: any | Promise | | removeElementInArray | Get data from a collection by id and remove the specified element in an array field | collection: string, id: string, arrayFieldName: string, Value: any | Promise | | getCollection<T, R = T> | Get data collection that refers to the specified collection path. When the response class is informed, the return data will be transformed to it. | collection: string, options?: Options<T>, ResponseClass?: new () => R | Promise<R[]> | | getById<T, R = T> | Get data from the collection by id. | collection: string, id: string, ResponseClass?: new () => R | Promise<R> | | getByValue<T, R = T> | Get data collection filtered by value. When the response class is informed, the return data will be transformed to it. | collection: string, fieldPath: string, value: any, whereFilter?: WhereFilterOp, ResponseClass?: new () => R | Promise<R[]> | | getByValueOrdered<T, R = T> | Get data collection ordinated and filtered by value. When the response class is informed, the return data will be transformed to it. | collection: string, fieldPath: string, whereFilter: WhereFilterOp, value: any, fieldOrder: string, direction?: OrderByDirection, ResponseClass?: new () => R | Promise<R[]> | | update<T> | Updates fields in the document referred to by this DocumentReference. Note. The document ID must exist in the data sent | collection: string, data: T | Promise | | updateField<T, C = any> | Updates fields in the document referred to by this DocumentReference in a fieldPath or nestedFields. | collection: string, id: string, field: keyof T \| FieldNested<T, C>, value: any | Promise | | updateArray<T, C = any> | Updates array fields in the document referred to by this DocumentReference in a fieldPath or nestedFields. | collection: string, id: string, field: keyof T \| FieldNested<T, C>, prevValue: any, newValue: any | Promise | | remove | Deletes the document referred to by this DocumentReference. | collection: string, id: string | Promise | | exists | True if the document exists. | collection: string, id: string | Promise | | getSizeCollection | Return the size of the collection. | collection: string, options?: Options<T> | Promise<number> | | getPaginatedCollection<T, F, R = T> | Get batch data collection that refers to the specified collection path. Note: The firestore requires indexes for queries with filters and sorting, if applicable, you will need to create them. When the response class is informed, the return data will be transformed to it. | collection: string, queryParams?: any, FilterClass?: new () => F, minimumSizeToPaginated?: number, options?: Options<T>, ResponseClass?: new () => R | Promise<R[]> | | getPaginatedArray<T, A, R = A> | Get the paginated array of a document that refers to the specified collection path. | collection: string, id: string, field: keyof T, pageNumber: number, pageSize?: number, minimumSizeToPaginated?: number, ResponseClass?: new () => R | Promise<R[]> |

Transaction

| Function | Description | Param | | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | | executeTransaction<T> | Start a new transaction. All the methods executed in transaction function will be in the transaction context and will be executed through the param transaction that is a function. Is used the runTransaction function from the Firestore database, because of this exists the same limitations. E.g, read functions can't be executed after the functions that modify data. | transaction : (t: any) => Promise<T> | | clearTransaction | This method cleans the context transactional. | | setTransaction | This method setting the transaction in the context. | transaction: Transaction["transaction"] |

Usage

...
   const repository = this.repository;

   const transaction = async (t: any) => {
      repository.setTransaction(t);

	  const data = await repository.getById<IFake, FakeResponse>(
        dynamicallyCollection,
        "123456",
        FakeResponse,
      );

      await repository.insertWithId<IFake>(dynamicallyCollection, fake);

      await repository.remove(dynamicallyCollection, "23021990");
    };

    const response = await repository.executeTransaction(transaction);
...

Types

| Type | Options | | ------------------ | --------------------------------------------------------------------------------------- | | WhereFilterOp | <, <=, ==, !=, >=, >, array-contains, in, array-contains-any | | FilterOperator | <, <=, ==, !=, >=, >, array-contains, in, array-contains-any, range | | OrderByDirection | desc, asc | | DialectType | Firestore, Firebase |