GithubHelp home page GithubHelp logo

nestjs / azure-database Goto Github PK

View Code? Open in Web Editor NEW
88.0 6.0 40.0 4.62 MB

Azure Database (Table Storage and more) module for Nest framework (node.js) ☁️

Home Page: https://nestjs.com

License: MIT License

TypeScript 98.39% JavaScript 1.61%
nestjs azure-table-storage nodejs typescript javascript nest azure cloud database

azure-database's Introduction

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads Travis Linux Coverage Discord Backers on Open Collective Sponsors on Open Collective

Description

Azure Database (Table Storage, Cosmos DB and more) module for Nest framework (node.js)

Tutorial

Learn how to get started with Azure table storage for NestJS

Before Installation

For Table Storage

  1. Create a Storage account and resource (read more)
  2. For Table Storage, In the Azure Portal, go to Dashboard > Storage > your-storage-account.
  3. Note down the "Storage account name" and "Connection string" obtained at Access keys under Settings tab.

For Cosmos DB

  1. Create a Cosmos DB account and resource (read more)
  2. For Cosmos DB, In the Azure Portal, go to Dashboard > Azure Cosmos DB > your-cosmos-db-account.
  3. Note down the "URI" and "Primary Key" obtained at Keys under Settings tab.

Installation

$ npm i --save @nestjs/azure-database

Usage

For Azure Table Storage support

  1. Create or update your existing .env file with the following content:
AZURE_STORAGE_CONNECTION_STRING=
  1. IMPORTANT: Make sure to add your .env file to your .gitignore! The .env file MUST NOT be versioned on Git.

  2. Make sure to include the following call to your main file:

if (process.env.NODE_ENV !== 'production') require('dotenv').config();

This line must be added before any other imports!

Example

Prepare your entity

  1. Create a new feature module, eg. with the nest CLI:
$ nest generate module contact
  1. Create a Data Transfer Object (DTO) inside a file named contact.dto.ts:
export class ContactDTO {
  name: string;
  message: string;
}
  1. Create a file called contact.entity.ts and describe the entity model using the provided decorators:
  • @EntityPartitionKey(value: string): Represents the PartitionKey of the entity (required).

  • @EntityRowKey(value: string): Represents the RowKey of the entity (required).

  • @EntityInt32(value?: string): For signed 32-bit integer values.

  • @EntityInt64(value?: string): For signed 64-bit integer values.

  • @EntityBinary(value?: string): For binary (blob) data.

  • @EntityBoolean(value?: string): For true or false values.

  • @EntityString(value?: string): For character data.

  • @EntityDouble(value?: string): For floating point numbers with 15 digit precision.

  • @EntityDateTime(value?: string): For time of day.

For instance, the shape of the following entity:

import { EntityPartitionKey, EntityRowKey, EntityString } from '@nestjs/azure-database';

@EntityPartitionKey('ContactID')
@EntityRowKey('ContactName')
export class Contact {
  @EntityString() name: string;
  @EntityString() message: string;
}

Will be automatically converted to:

{
  "PartitionKey": { "_": "ContactID", "$": "Edm.String" },
  "RowKey": { "_": "ContactName", "$": "Edm.String" },
  "name": { "_": undefined, "$": "Edm.String" },
  "message": { "_": undefined, "$": "Edm.String" }
}

Note: The provided entity type annotations represent the Entity Data Model types.

  1. Import the AzureTableStorageModule inside your Nest feature module contact.module.ts:
import { Module } from '@nestjs/common';
import { AzureTableStorageModule } from '@nestjs/azure-database';
import { ContactController } from './contact.controller';
import { ContactService } from './contact.service';
import { Contact } from './contact.entity';

@Module({
  imports: [AzureTableStorageModule.forFeature(Contact)],
  providers: [ContactService],
  controllers: [ContactController],
})
export class ContactModule {}

You can optionally pass in the following arguments:

AzureTableStorageModule.forFeature(Contact, {
  table: 'AnotherTableName',
  createTableIfNotExists: true,
});
  • table: string: The name of the table. If not provided, the name of the Contact entity will be used as a table name
  • createTableIfNotExists: boolean: Whether to automatically create the table if it doesn't exists or not:
    • If true the table will be created during the startup of the app.
    • If false the table will not be created. You will have to create the table by yourself before querying it!

CRUD operations

  1. Create a service that will abstract the CRUD operations:
$ nest generate service contact
  1. Use the @InjectRepository(Contact) to get an instance of the Azure Repository for the entity definition created earlier:
import { Injectable } from '@nestjs/common';
import { Repository, InjectRepository } from '@nestjs/azure-database';
import { Contact } from './contact.entity';

@Injectable()
export class ContactService {
  constructor(
    @InjectRepository(Contact)
    private readonly contactRepository: Repository<Contact>,
  ) {}
}

The AzureTableStorageRepository provides a couple of public APIs and Interfaces for managing various CRUD operations:

CREATE

create(entity: T, rowKeyValue?: string): Promise<T>: creates a new entity.

  @Post()
  async create(contact: Contact, rowKeyValue: string): Promise<Contact> {
    //if rowKeyValue is null, rowKeyValue will generate a UUID
    return this.contactRepository.create(contact, rowKeyValue)
  }
READ

find(rowKey: string, entity: Partial<T>): Promise<T>: finds one entity using its RowKey.

  @Get(':rowKey')
  async getContact(@Param('rowKey') rowKey) {
    try {
      return await this.contactRepository.find(rowKey, new Contact());
    } catch (error) {
      // Entity not found
      throw new UnprocessableEntityException(error);
    }
  }

findAll(tableQuery?: azure.TableQuery, currentToken?: azure.TableService.TableContinuationToken): Promise<AzureTableStorageResultList<T>>: finds all entities that match the given query (return all entities if no query provided).

  @Get()
  async getAllContacts() {
    return await this.contactRepository.findAll();
  }
UPDATE

update(rowKey: string, entity: Partial<T>): Promise<T>: Updates an entity. It does a partial update.

  @Put(':rowKey')
  async saveContact(@Param('rowKey') rowKey, @Body() contactData: ContactDTO) {
    try {
      const contactEntity = new Contact();
      // Disclaimer: Assign only the properties you are expecting!
      Object.assign(contactEntity, contactData);

      return await this.contactRepository.update(rowKey, contactEntity);
    } catch (error) {
      throw new UnprocessableEntityException(error);
    }
  }
  @Patch(':rowKey')
  async updateContactDetails(@Param('rowKey') rowKey, @Body() contactData: Partial<ContactDTO>) {
    try {
      const contactEntity = new Contact();
      // Disclaimer: Assign only the properties you are expecting!
      Object.assign(contactEntity, contactData);

      return await this.contactRepository.update(rowKey, contactEntity);
    } catch (error) {
      throw new UnprocessableEntityException(error);
    }
  }
DELETE

delete(rowKey: string, entity: T): Promise<AzureTableStorageResponse>: Removes an entity from the database.

  @Delete(':rowKey')
  async deleteDelete(@Param('rowKey') rowKey) {
    try {
      const response = await this.contactRepository.delete(rowKey, new Contact());

      if (response.statusCode === 204) {
        return null;
      } else {
        throw new UnprocessableEntityException(response);
      }
    } catch (error) {
      throw new UnprocessableEntityException(error);
    }
  }

For Azure Cosmos DB support

  1. Create or update your existing .env file with the following content:
AZURE_COSMOS_DB_NAME=
AZURE_COSMOS_DB_ENDPOINT=
AZURE_COSMOS_DB_KEY=
  1. IMPORTANT: Make sure to add your .env file to your .gitignore! The .env file MUST NOT be versioned on Git.

  2. Make sure to include the following call to your main file:

if (process.env.NODE_ENV !== 'production') require('dotenv').config();

This line must be added before any other imports!

Example

Note: Check out the CosmosDB example project included in the sample folder

Prepare your entity

  1. Create a new feature module, eg. with the nest CLI:
$ nest generate module event
  1. Create a Data Transfer Object (DTO) inside a file named event.dto.ts:
export class EventDTO {
  name: string;
  type: string;
  date: Date;
  location: Point;
}
  1. Create a file called event.entity.ts and describe the entity model using the provided decorators:
  • @CosmosPartitionKey(value: string): Represents the PartitionKey of the entity (required).

  • @CosmosDateTime(value?: string): For DateTime values.

For instance, the shape of the following entity:

import { CosmosPartitionKey, CosmosDateTime, Point } from '@nestjs/azure-database';

@CosmosPartitionKey('type')
export class Event {
  id?: string;
  type: string;
  @CosmosDateTime() createdAt: Date;
  location: Point;
}

Will be automatically converted to:

{
  "type": "Meetup",
  "createdAt": "2019-11-15T17:05:25.427Z",
  "position": {
    "type": "Point",
    "coordinates": [2.3522, 48.8566]
  }
}
  1. Import the AzureCosmosDbModule inside your Nest feature module event.module.ts:
import { Module } from '@nestjs/common';
import { AzureCosmosDbModule } from '@nestjs/azure-database';
import { EventController } from './event.controller';
import { EventService } from './event.service';
import { Event } from './event.entity';

@Module({
  imports: [
    AzureCosmosDbModule.forRoot({
      dbName: process.env.AZURE_COSMOS_DB_NAME,
      endpoint: process.env.AZURE_COSMOS_DB_ENDPOINT,
      key: process.env.AZURE_COSMOS_DB_KEY,
    }),
    AzureCosmosDbModule.forFeature([{ dto: Event }]),
  ],
  providers: [EventService],
  controllers: [EventController],
})
export class EventModule {}

CRUD operations

  1. Create a service that will abstract the CRUD operations:
$ nest generate service event
  1. Use the @InjectModel(Event) to get an instance of the Azure Cosmos DB Container for the entity definition created earlier:
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/azure-database';
import { Event } from './event.entity';

@Injectable()
export class EventService {
  constructor(
    @InjectModel(Event)
    private readonly eventContainer,
  ) {}
}

The Azure Cosmos DB Container provides a couple of public APIs and Interfaces for managing various CRUD operations:

CREATE

create(entity: T): Promise<T>: creates a new entity.

  @Post()
  async create(event: Event): Promise<Event> {
      return this.eventContainer.items.create(event)
  }
READ

query<T>(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<T>: run a SQL Query to find a document.

  @Get(':id')
  async getContact(@Param('id') id) {
    try {
       const querySpec = {
           query: "SELECT * FROM root r WHERE [email protected]",
           parameters: [
             {
               name: "@id",
               value: id
             }
           ]
         };
        const { resources } = await this.eventContainer.items.query<Event>(querySpec).fetchAll()
         return resources
    } catch (error) {
      // Entity not found
      throw new UnprocessableEntityException(error);
    }
  }
UPDATE

read<T>(options?: RequestOptions): Promise<ItemResponse<T>>: Get a document. replace<T>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>: Updates a document.

  @Put(':id')
  async saveEvent(@Param('id') id, @Body() eventData: EventDTO) {
    try {
      const { resource: item } = await this.eventContainer.item<Event>(id, 'type').read()

      // Disclaimer: Assign only the properties you are expecting!
      Object.assign(item, eventData);

      const { resource: replaced } = await this.eventContainer
       .item(id, 'type')
       .replace<Event>(item)
      return replaced
    } catch (error) {
      throw new UnprocessableEntityException(error);
    }
  }
DELETE

delete<T>(options?: RequestOptions): Promise<ItemResponse<T>>: Removes an entity from the database.

  @Delete(':id')
  async deleteEvent(@Param('id') id) {
    try {
      const { resource: deleted } = await this.eventContainer
       .item(id, 'type')
       .delete<Event>()

      return deleted;
    } catch (error) {
      throw new UnprocessableEntityException(error);
    }
  }

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

azure-database's People

Contributors

0xflotus avatar abouroubi avatar beneiltis avatar caucik avatar dantehemerson avatar dependabot[bot] avatar kamilmysliwiec avatar manekinekko avatar markpieszak avatar marsonya avatar mdilshan avatar nostap avatar renovate-bot avatar renovate[bot] avatar sergfa avatar sheikalthaf avatar sinedied avatar tabs-not-spaces avatar tony133 avatar videlalvaro avatar wodcz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

azure-database's Issues

Cosmos DB Mongodb API

This package is also working with Cosmos DB mongodb API? Or it's preferable to use mongoose?

Connection to Cosmos Hangs

I'm submitting a bug/request for help


[ ] Regression 
[ x] Bug report
[ ] Feature request
[ x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When nest starts up and the cosmos connection is created it hangs and times out. Tried same creds with c# and explicit gateway mode and its working.

Expected behavior

nest azure-database module can connect to cosmos hosted in azure.

Minimal reproduction of the problem with instructions

  1. Create a cosmos db in azure.
  2. Enter in the connection details in the AzureCosmosDbModule setup.
  3. Start up the app.
  4. Hit any path in nest where controller uses cosmos connection. App hangs and times out.

What is the motivation / use case for changing the behavior?

ReadMe

Environment


Nest version: 8.0.0

 
For Tooling issues:
- Node version: 16.13.1
- Platform:  Mac

Others:

Class 'AzureTableStorageService' incorrectly implements interface 'TableService'

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I followed the Cosmos DB section of this guide. I am using
When running the app with nest start, I get the following compilation error:

node_modules/@nestjs/azure-database/dist/table-storage/azure-table.service.d.ts:2:22 - error TS2420: Class 'AzureTableStorageService' incorrectly implements interface 'TableService'.
  Property 'host' is missing in type 'AzureTableStorageService' but required in type 'TableService'.

2 export declare class AzureTableStorageService implements azure.TableService {
                       ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/azure-storage/typings/azure-storage/azure-storage.d.ts:9330:11
    9330           host: StorageHost;
                   ~~~~
    'host' is declared here.

Found 1 error(s).

The error seems entirely contained inside of Azure's dependency, so I am guessing it is a versioning problem because I can't think of any code I wrote that would cause this.

Expected behavior

Normally with this kind of guide I would run in to some issue with Azure configuration or a problem with my code. Not a problem within @nestjs/azure-database

Minimal reproduction of the problem with instructions

Follow the guide as mentioned. Package json is below:
{ "name": "xxxxxxx", "version": "0.0.1", "description": "", "author": "", "private": true, "license": "UNLICENSED", "scripts": { "prebuild": "rimraf dist", "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { "@nestjs/azure-database": "^2.0.1", "@nestjs/common": "^7.6.13", "@nestjs/config": "^0.6.3", "@nestjs/core": "^7.6.13", "@nestjs/passport": "^7.1.5", "@nestjs/platform-express": "^7.6.13", "@nestjs/swagger": "^4.7.15", "@types/passport-azure-ad": "^4.0.8", "class-transformer": "^0.4.0", "class-validator": "^0.13.1", "dotenv": "^8.2.0", "passport": "^0.4.1", "passport-azure-ad": "^4.3.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^6.6.6" }, "devDependencies": { "@nestjs/cli": "^7.5.6", "@nestjs/schematics": "^7.2.7", "@nestjs/testing": "^7.6.13", "@types/express": "^4.17.11", "@types/jest": "^26.0.20", "@types/node": "^14.14.31", "@types/supertest": "^2.0.10", "@typescript-eslint/eslint-plugin": "^4.15.2", "@typescript-eslint/parser": "^4.15.2", "eslint": "^7.20.0", "eslint-config-prettier": "^8.1.0", "eslint-plugin-prettier": "^3.3.1", "jest": "^26.6.3", "prettier": "^2.2.1", "supertest": "^6.1.3", "ts-jest": "^26.5.2", "ts-loader": "^8.0.17", "ts-node": "^9.1.1", "tsconfig-paths": "^3.9.0", "typescript": "^4.1.5" }, "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".*\\.spec\\.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, "collectCoverageFrom": [ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", "testEnvironment": "node" } }

What is the motivation / use case for changing the behavior?

I need to get this app to compile so I can actually write code.

Environment


Nest version: 2.0.1

 
For Tooling issues:
- Node version: v14.15.5  
- Platform:  macOS Big Sur 11.1

Others:

Using intelliJ 2020.3.1 and nestJS version 7.5.6

Invalid Gitter Chatroom Link in the Badge is Invalid

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

The Gitter badge in the README.md file is invalid.

Expected behavior

All other Repos in this Organisation have a working discord link. I am guessing this one must have a discord link.

run failure with cosmosdb example

pwd
.../azure-database/sample/cosmos-db

npm i
npm run build
npm run start

> [email protected] start /Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db
> nest start

[Nest] 72867   - 04/13/2020, 1:04:02 AM   [NestFactory] Starting Nest application...
[Nest] 72867   - 04/13/2020, 1:04:02 AM   [InstanceLoader] AppModule dependencies initialized +17ms
[Nest] 72867   - 04/13/2020, 1:04:02 AM   [InstanceLoader] AzureCosmosDbModule dependencies initialized +1ms
[Nest] 72867   - 04/13/2020, 1:04:02 AM   [ExceptionHandler] Nest can't resolve dependencies of the ContactService (?). Please make sure that the argument ContactRepository at index [0] is available in the ContactModule context.

Potential solutions:
- If ContactRepository is a provider, is it part of the current ContactModule?
- If ContactRepository is exported from a separate @Module, is that module imported within ContactModule?
  @Module({
    imports: [ /* the Module containing ContactRepository */ ]
  })
 +1ms
Error: Nest can't resolve dependencies of the ContactService (?). Please make sure that the argument ContactRepository at index [0] is available in the ContactModule context.

Potential solutions:
- If ContactRepository is a provider, is it part of the current ContactModule?
- If ContactRepository is exported from a separate @Module, is that module imported within ContactModule?
  @Module({
    imports: [ /* the Module containing ContactRepository */ ]
  })

    at Injector.lookupComponentInParentModules (/Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db/node_modules/@nestjs/core/injector/injector.js:191:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Injector.resolveComponentInstance (/Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db/node_modules/@nestjs/core/injector/injector.js:147:33)
    at async resolveParam (/Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db/node_modules/@nestjs/core/injector/injector.js:101:38)
    at async Promise.all (index 0)
    at async Injector.resolveConstructorParams (/Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db/node_modules/@nestjs/core/injector/injector.js:116:27)
    at async Injector.loadInstance (/Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db/node_modules/@nestjs/core/injector/injector.js:80:9)
    at async Injector.loadProvider (/Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db/node_modules/@nestjs/core/injector/injector.js:37:9)
    at async Promise.all (index 3)
    at async InstanceLoader.createInstancesOfProviders (/Volumes/data/workspace/draft/azure-db/azure-database/sample/cosmos-db/node_modules/@nestjs/core/injector/instance-loader.js:42:9)

Current behavior

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment

node -v
v12.16.2

 npm -v
6.14.4

macos 10.14.6

forFeature second argument isn't optional as the doc is specifying

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

FROM DOC:

You can optionally pass in the following arguments:

AzureTableStorageModule.forFeature(Contact, {
  table: 'AnotherTableName',
  createTableIfNotExists: true,
})

Expected behavior

Should be optional !

Using TableQuery filters as parameter of `findAll()` doesn't work

I'm submitting a...


[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Using TableQuery filters as parameter of findAll() doesn't work:

this.entityRepository
        .findAll(new TableQuery().where(filters));

It is because, even if it is not the case, the query is already specified within the findAll() on this line:

tableQuery = this.query || tableQuery;

The query is already specified because the getter return the queryInstance by default:

return this._query || this.manager.queryInstance;

Alternative solution: Specify the query directly into the repository:

this.entityRepository
        .where(filters)
        .findAll();

Improve the find() API

I'm submitting a...


[x] Feature request

Current behavior

this.catRepository.find(rowKey, new Cat());

Expected behavior

this.catRepository.find(new Cat({rowKey}));

Add support for CosmosDB

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

This package only supports Table Storage.

Expected behavior

We need to support the Cosmos DB API.

Others:


Here are some resources links:

Notes:

Ideally, we would need to design a public API that is somehow similar to the current AzureTableStorageModule. We want the user to simply switch from AzureTableStorageModule to AzureCosmosDBModule without impacting their code.

To some extent, the user should be able to follow the Getting started and simply use the new AzureCosmosDBModule module.

How can a Table Query be performed on Azure Table Storage

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[ X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I would like to query the Azure Table Storage Database using a Table Query. There isn't any documentation here on how that can be achieved. My approach (probably wrong) has been to do the following:


import { TableQuery } from 'azure-storage';
import { Repository } from '@nestjs/azure-database';

export class SomeService {
    constructor(
        @InjectRepository(EntitySchema)
        private readonly entityRepo: Repository
    ) {}
    
   async findSpecific(entityProperty: string): Promise {
       const query = new TableQuery();
       return await this.entityRepo.findAll(query.where(`property == ${entityPropery}`));
   }

The error I am getting from this is: The requested operation is not implemented on the specified resource.

Expected behavior

The query returns the defined results.

Environment


Nest version: 8.2.3

 
For Tooling issues:
- Node version: v17.2.0
- Platform:  MacOS

Others:

Azure cosmos doesn't have Keys under settings anymore

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

In the documentation it said to get key from keys section under settings, seems it doesn't exists anymore, there is a connection string section, not sure what should be put in the .env file

image

image

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: 7

 
For Tooling issues:
- Node version: 12
- Platform:  Max

Others:

Dynamic value to the decorator like `EntityPartitionKey` | `EntityRowKey`?

I'm submitting a...

It is possible to pass the dynamic value to the decorator likeEntityPartitionKey | EntityRowKey?


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

@EntityPartitionKey('CatID') is accepting the string but my paritionKey will be dynamic. It is based on the Entity value.

Expected behavior

Something i want is like
@EntityPartitionKey(data => data.Id + data.Name)

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: 6.9.0

 
For Tooling issues:
- Node version:   v10.17.0
- Platform:   Linux

Others:

Azure table : concurrent update strange behavior

I'm submitting a...


[ ] Regression 
[X ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

We have one table with several entities
Some entities have the same partitionKey.
Each entities have a unique RowKey

When we process two updates at the same time with same PartitionKey but different RowKey we have a strange behavior => the two entities are mixed with same content

I noticed the lib use azure replaceEntity to do an update. When testing same case with Microsoft lib and mergeEntity function we don t have the issue, but I would prefer to use nest lib as it’s integration is more interesting with Nest

Expected behavior

Each updated entities are correctly and independently updated

Minimal reproduction of the problem with instructions

Create to update at the same time

What is the motivation / use case for changing the behavior?

Environment


Nest version: 6.9 to 7.0

 
For Tooling issues:
- Node version: 10.14 and + 
- Platform:  Mac. Linux and Windows

Others:
Package manager : npm

Not getting cosmosDb module on npm install

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Expected behavior

When running

npm i --save @nestjs/azure-database

i do not get the cosmos db part, could you please update the registry on npm?

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: 12.18    
- npm version: 6.14
- Platform: Mac 

Others:

azure-storage is deprecated

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Connection string set to UseDevelopmentStorage=true results in error message Credentials must be provided when creating a service client.

Expected behaviour

Connection strings work as documented by Microsoft

Minimal reproduction of the problem with instructions

See current behaviour

What is the motivation / use case for changing the behavior?

For the particular example: Local development using azurite
In general: azure-storage module is officially deprecated. Microsoft doesn't recommend to use this module anymore

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Error when using connectionString in forRoot instead of .env

I'm submitting a...


[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Based on your doc, it should be possible to use a forRoot on the main module to configure the connection but when I use it:

app.module.ts:

@Module({
  imports: [
    AzureTableStorageModule.forRoot({
      connectionString:
        'DefaultEndpointsProtocol=**********************************',
    }),
    CatModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

cat.module.ts:

@Module({
  imports: [
    AzureTableStorageModule.forFeature(Cat, {
      table: 'Cat',
      createTableIfNotExists: true,
    }),
  ],
  providers: [CatService],
  controllers: [CatController],
})
export class CatModule {}

I got an error about a provider not available:

[Nest] 26448   - 12/18/2019, 8:41:44 AM   [AzureTableStorage] Create new TableService instance
[Nest] 26448   - 12/18/2019, 8:41:44 AM   [ExceptionHandler] Nest can't resolve dependencies of the AzureTableStorageRepository (AzureTableStorageService, ?). Please make sure that the argument AZURE_TABLE_STORAGE_NAME at index [1] is available in the AzureTableStorageModule context.

Potential solutions:
- If AZURE_TABLE_STORAGE_NAME is a provider, is it part of the current AzureTableStorageModule?
- If AZURE_TABLE_STORAGE_NAME is exported from a separate @Module, is that module imported within AzureTableStorageModule?
  @Module({
    imports: [ /* the Module containing AZURE_TABLE_STORAGE_NAME */ ]
  })
 +2ms
Error: Nest can't resolve dependencies of the AzureTableStorageRepository (AzureTableStorageService, ?). Please make sure that the argument AZURE_TABLE_STORAGE_NAME at index [1] is available in the AzureTableStorageModule context.

Potential solutions:
- If AZURE_TABLE_STORAGE_NAME is a provider, is it part of the current AzureTableStorageModule?
- If AZURE_TABLE_STORAGE_NAME is exported from a separate @Module, is that module imported within AzureTableStorageModule?
  @Module({
    imports: [ /* the Module containing AZURE_TABLE_STORAGE_NAME */ ]
  })

    at Injector.lookupComponentInParentModules (/home/kiwi/dev/azure-db/node_modules/@nestjs/core/injector/injector.js:190:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Injector.resolveComponentInstance (/home/kiwi/dev/azure-db/node_modules/@nestjs/core/injector/injector.js:146:33)
    at async resolveParam (/home/kiwi/dev/azure-db/node_modules/@nestjs/core/injector/injector.js:100:38)
    at async Promise.all (index 1)
    at async Injector.resolveConstructorParams (/home/kiwi/dev/azure-db/node_modules/@nestjs/core/injector/injector.js:115:27)
    at async Injector.loadInstance (/home/kiwi/dev/azure-db/node_modules/@nestjs/core/injector/injector.js:79:9)
    at async Injector.loadProvider (/home/kiwi/dev/azure-db/node_modules/@nestjs/core/injector/injector.js:36:9)
    at async Promise.all (index 4)
    at async InstanceLoader.createInstancesOfProviders (/home/kiwi/dev/azure-db/node_modules/@nestjs/core/injector/instance-loader.js:41:9)

Expected behavior

I expect to not have any error when I am using forRoot instead of .env

Minimal reproduction of the problem with instructions

https://github.com/jogelin/nestjs-azure-database-sample/tree/issue-for-root

Add support for async module initialization

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Batch operations

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

No batch operations

Expected behavior

Batch operations for update/delete.

What is the motivation / use case for changing the behavior?

Currently, I am searching for a way to use batch operations for updating and deleting. I have not found any option for this in the package. Is it planned to be implemented? Is there any workaround?

getModelToken should be exported

getModelToken should be exported so that it's possible to provide stable test doubles.

Given service like this:

export class SomeService {
  constructor(@InjectModel(SomeEntity) private readonly container: Container) {}
}

What we have to do now:

Test.createTestingModule({
  providers: [
    SomeService,
    { provide: `${SomeEntity}AzureCosmosDbModel`, useValue: jest.mocked({}) },
  ],
});

How it should be:

Test.createTestingModule({
  providers: [
    SomeService,
    { provide: getModelToken(SomeEntity), useValue: jest.mocked({}) },
  ],
});

CosmosDB Error on version 9+

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

On npm run start:dev getting the following error -

ERROR [ExceptionHandler] Nest can't resolve dependencies of the AzureCosmosDbCoreModule (COSMOS_DB_CONNECTION_NAME, ?)

Others having the same issue - https://stackoverflow.com/questions/73731641/how-to-establish-cosmos-db-database-connection-with-nestjs-v9-0-0

Potential solutions:

  • If ModuleRef is a provider, is it part of the current AzureCosmosDbCoreModule?
  • If ModuleRef is exported from a separate @module, is that module imported within AzureCosmosDbCoreModule?
    @module({
    imports: [ /* the Module containing ModuleRef */ ]
    })

Error: Nest can't resolve dependencies of the AzureCosmosDbCoreModule (COSMOS_DB_CONNECTION_NAME, ?). Please make sure that the argument ModuleRef at index [1] is available in the AzureCosmosDbCoreModule context.

Minimum reproduction code

node 14 & 16, nestjs/common "^9.0.0"

Steps to reproduce

npm run start:dev

Using cosmos installation -

https://www.learmoreseekmore.com/2022/05/crud-operation-demo-on-nestjs-using-azure-cosmos-db.html

Expected behavior

Fetch data from cosmos db successfully.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

9.1.2

Packages versions

{
    "@azure/cosmos": "^3.17.1",
    "@azure/functions": "^1.0.3",
    "@nestjs/azure-database": "^2.3.0",
    "@nestjs/azure-func-http": "^0.8.0",
    "@nestjs/common": "^9.1.2",
    "@nestjs/config": "^2.2.0",
    "@nestjs/core": "^9.1.2",
    "@nestjs/mapped-types": "*",
    "@nestjs/platform-express": "^9.1.2",
    "@nestjs/sequelize": "^9.0.0",
    "@nestjs/swagger": "^6.1.2",
    "json2csv": "^5.0.7",
    "jspdf": "^2.5.1",
    "jspdf-autotable": "^3.5.25",
    "moment": "^2.29.4",
    "mysql2": "^2.3.3",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0",
    "sequelize": "^6.21.4",
    "sequelize-typescript": "^2.1.3",
    "tedious": "^15.0.1"
  }

Node.js version

16.16.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency ts-jest to v29.0.5
  • chore(deps): update commitlint monorepo to v17.4.4 (@commitlint/cli, @commitlint/config-angular)
  • chore(deps): update dependency @nestjs/testing to v9.3.10
  • chore(deps): update dependency eslint to v8.36.0
  • chore(deps): update dependency eslint-config-prettier to v8.7.0
  • chore(deps): update dependency eslint-plugin-import to v2.27.5
  • chore(deps): update dependency lint-staged to v13.2.0
  • chore(deps): update dependency prettier to v2.8.4
  • chore(deps): update dependency typescript to v4.9.5
  • chore(deps): update jest monorepo to v29.5.0 (@types/jest, jest)
  • chore(deps): update typescript-eslint monorepo to v5.55.0 (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • chore(deps): update dependency @nestjs/cli to v9
  • chore(deps): update dependency typescript to v5
  • fix(deps): update dependency rimraf to v4
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • cimg/node 17.9
  • cimg/node 17.9
npm
package.json
  • @azure/cosmos ^3.16.2
  • @azure/ms-rest-js ^2.6.1
  • @nestjs/common ^8.0.0
  • @nestjs/core ^8.0.0
  • azure-storage ^2.10.7
  • @commitlint/cli 17.2.0
  • @commitlint/config-angular 17.2.0
  • @nestjs/testing 9.1.6
  • @types/jest 29.2.2
  • @types/node 18.11.9
  • @typescript-eslint/eslint-plugin 5.42.1
  • @typescript-eslint/parser 5.42.1
  • dotenv 16.0.3
  • eslint 8.27.0
  • eslint-config-prettier 8.5.0
  • eslint-plugin-import 2.26.0
  • husky 8.0.1
  • jest 29.2.2
  • lint-staged 13.0.3
  • prettier 2.7.1
  • reflect-metadata 0.1.13
  • rimraf 3.0.2
  • supertest 6.3.1
  • ts-jest 29.0.3
  • typescript 4.8.4
  • @nestjs/common ^7.0.0 || ^8.0.0 || ^9.0.0
  • @nestjs/core ^7.0.0 || ^8.0.0 ||^9.0.0
sample/cosmos-db/package.json
  • @nestjs/common ^8.0.0
  • @nestjs/core ^8.0.0
  • @nestjs/platform-express ^8.0.0
  • dotenv ^16.0.0
  • reflect-metadata ^0.1.13
  • rimraf ^3.0.0
  • rxjs ^7.0.0
  • @nestjs/cli ^8.0.0
  • @nestjs/schematics ^9.0.0
  • @nestjs/testing ^8.0.0
  • @types/express ^4.17.2
  • @types/jest ^29.0.0
  • @types/node ^18.0.0
  • @types/supertest ^2.0.8
  • jest ^29.0.0
  • prettier ^2.0.0
  • supertest ^6.0.0
  • ts-jest ^29.0.0
  • ts-loader ^9.0.0
  • ts-node ^10.0.0
  • tsconfig-paths ^4.0.0
  • tslint ^6.0.0
  • typescript ^4.0.0
sample/table-storage/package.json
  • @nestjs/common ^8.0.0
  • @nestjs/core ^8.0.0
  • @nestjs/platform-express ^8.0.0
  • reflect-metadata ^0.1.13
  • rimraf ^3.0.0
  • rxjs ^7.0.0
  • @nestjs/cli ^8.0.0
  • @nestjs/schematics ^9.0.0
  • @nestjs/testing ^8.0.0
  • @types/express ^4.17.3
  • @types/jest ^29.0.0
  • @types/node ^18.0.0
  • @types/supertest ^2.0.8
  • jest ^29.0.0
  • prettier ^2.2.1
  • supertest ^6.0.0
  • ts-jest ^29.0.0
  • ts-loader ^9.0.0
  • ts-node ^10.0.0
  • tsconfig-paths ^4.0.0
  • tslint ^6.0.0
  • typescript ^4.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

RowKey doesn't take the real config

I am trying the azure database sample, and it was generated with default uuid string instead ContactName RowKey


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: 7.0.3

 
For Tooling issues:
- Node version:  10.14  
- Platform:  Windows 

Others:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.