2.1.2 • Published 3 years ago

nosql-easy v2.1.2

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

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

FunctionDescriptionParamReturn
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 () => RPromise<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 () => RPromise<R>
insertElementInArrayAdd a new document to this collection with the specified data, and update fields into document referredcollection: string, id: string, arrayFieldName: string, Value: anyPromise
removeElementInArrayGet data from a collection by id and remove the specified element in an array fieldcollection: string, id: string, arrayFieldName: string, Value: anyPromise
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 () => RPromise<R[]>
getById<T, R = T>Get data from the collection by id.collection: string, id: string, ResponseClass?: new () => RPromise<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 () => RPromise<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 () => RPromise<R[]>
update<T>Updates fields in the document referred to by this DocumentReference. Note. The document ID must exist in the data sentcollection: string, data: TPromise
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: anyPromise
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: anyPromise
removeDeletes the document referred to by this DocumentReference.collection: string, id: stringPromise
existsTrue if the document exists.collection: string, id: stringPromise
getSizeCollectionReturn 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 () => RPromise<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 () => RPromise<R[]>

Transaction

FunctionDescriptionParam
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>
clearTransactionThis method cleans the context transactional.
setTransactionThis 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

TypeOptions
WhereFilterOp<, <=, ==, !=, >=, >, array-contains, in, array-contains-any
FilterOperator<, <=, ==, !=, >=, >, array-contains, in, array-contains-any, range
OrderByDirectiondesc, asc
DialectTypeFirestore, Firebase
2.1.2

3 years ago

2.1.1

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.0.1

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago