azure-database:用于Nest框架(node.js)的Azure数据库(表存储等)模块

  • I7_765781
    了解作者
  • 530.2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-29 08:33
    上传日期
一个渐进式的框架,用于构建高效且可扩展的服务器端应用程序。 描述 适用于框架(node.js)的Azure数据库(, 等)模块 讲解 了解如何开始使用 安装前 用于表存储 创建一个存储帐户和资源() 对于,在,转到“仪表板”>“存储”>“您的存储帐户” 。 记下在“设置”选项卡下的“访问”键上获得的“存储帐户名”和“连接字符串”。 对于Cosmos DB 创建一个Cosmos DB帐户和资源() 对于 ,在,转到“仪表板”>“ Azure Cosmos DB”>“ your-cosmos-db-account” 。 记下“URI”,并在按键设置选项卡下获得的“主键”。 安装 $ npm i --save @nestjs/azure-database 用法 对于Azure表存储支持 使用以下内容创建或更新您现有的.env文件: AZURE_STORAGE_CONNECTION_STRING= 重要说明:确保将.env文件添加到.gitignore! .env文件一定不能在Git上进行版本控制。 确保对主文件包含以下调用: if ( process . env . NOD
azure-database-master.zip
内容介绍
<p align="center"> <a href="http://nestjs.com/" target="blank" rel='nofollow' onclick='return false;'><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a> </p> [travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master [travis-url]: https://travis-ci.org/nestjs/nest [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux [linux-url]: https://travis-ci.org/nestjs/nest <p align="center">A progressive <a href="http://nodejs.org" target="blank" rel='nofollow' onclick='return false;'>Node.js</a> framework for building efficient and scalable server-side applications.</p> <p align="center"> <a href="https://www.npmjs.com/~nestjscore" rel='nofollow' onclick='return false;'><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> <a href="https://www.npmjs.com/~nestjscore" rel='nofollow' onclick='return false;'><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> <a href="https://www.npmjs.com/~nestjscore" rel='nofollow' onclick='return false;'><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a> <a href="https://travis-ci.org/nestjs/nest" rel='nofollow' onclick='return false;'><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a> <a href="https://travis-ci.org/nestjs/nest" rel='nofollow' onclick='return false;'><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a> <a href="https://coveralls.io/github/nestjs/nest?branch=master" rel='nofollow' onclick='return false;'><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a> <a href="https://discord.gg/G7Qnnhy" target="_blank" rel='nofollow' onclick='return false;'><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> <a href="https://opencollective.com/nest#backer" rel='nofollow' onclick='return false;'><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> <a href="https://opencollective.com/nest#sponsor" rel='nofollow' onclick='return false;'><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> <a href="https://paypal.me/kamilmysliwiec" rel='nofollow' onclick='return false;'><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a> <a href="https://twitter.com/nestframework" rel='nofollow' onclick='return false;'><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a> </p> <!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer) [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--> ## Description Azure Database ([Table Storage](http://bit.ly/nest_azure-storage-table), [Cosmos DB](https://azure.microsoft.com/en-us/services/cosmos-db/) and more) module for [Nest](https://github.com/nestjs/nest) framework (node.js) ## Tutorial Learn how to get started with [Azure table storage for NestJS](https://trilon.io/blog/nestjs-nosql-azure-table-storage) ## Before Installation For Table Storage 1. Create a Storage account and resource ([read more](http://bit.ly/nest_new-azure-storage-account)) 1. For [Table Storage](http://bit.ly/nest_azure-storage-table), In the [Azure Portal](https://portal.azure.com), go to **Dashboard > Storage > _your-storage-account_**. 1. 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](https://azure.microsoft.com/en-us/services/cosmos-db/)) 1. For [Cosmos DB](http://bit.ly/nest_azure-storage-table), In the [Azure Portal](https://portal.azure.com), go to **Dashboard > Azure Cosmos DB > _your-cosmos-db-account_**. 1. Note down the "URI" and "Primary Key" obtained at **Keys** under **Settings** tab. ## Installation ```bash $ 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= ``` 2. **IMPORTANT: Make sure to add your `.env` file to your .gitignore! The `.env` file MUST NOT be versioned on Git.** 3. Make sure to include the following call to your main file: ```typescript if (process.env.NODE_ENV !== 'production') require('dotenv').config(); ``` > This line must be added before any other imports! ### Example #### Prepare your entity 0. Create a new feature module, eg. with the nest CLI: ```shell $ nest generate module contact ``` 1. Create a Data Transfer Object (DTO) inside a file named `contact.dto.ts`: ```typescript export class ContactDTO { name: string; message: string; } ``` 2. 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: ```typescript 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: ```json { "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][edm-types] types. 3. Import the `AzureTableStorageModule` inside your Nest feature module `contact.module.ts`: ```typescript 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: ```typescript 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 0. Create a service that will abstract the CRUD operations: ```shell $ nest generate service contact ``` 1. Use the `@InjectRepository(Contact)` to get an instance of the Azure `Repository` for the entity definition created earlier: ```typescript 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. ```typescript @Post() async create(contact: Contact, rowKeyValue: string): Promise<Contact> { //if rowKeyValue is null, rowKeyValue will generate a UUID return t
评论
    相关推荐
    • 用于Oauth2的简单Node.js客户端库-Node.js开发
      用于OAuth2的简单OAuth2 Node.js客户端库。 OAuth2允许用户通过第三方应用程序授予对受限资源的访问权限。 目录简单的OAuth2目录要求简单的OAuth2 OAuth2的Node.js客户端库。 OAuth2允许用户通过第三方应用程序授予...
    • Node.js-《Node.js入门教程》By流口水流
      这个课程不是文档式的,...而是在学习每个知识点后,提供个Node.js 实战例子来稳固这些知识点,希望可以通过每一节精心安排的课程,让 Node.js 的初学者们可以循序渐进地,有目的地开展 Node.js 的学习,少一点儿迷茫。
    • nforce:nforce是用于force.com,database.com和salesforce.com的node.js sa
      nforce是node.js,是force.com,database.com和salesforce.com的REST API包装器。 特征 简单的API 智能对象 辅助OAuth方法 简单的流媒体 单用户模式下的多用户设计 插件支持 安装 npm install nforce 用法 在您的...
    • Node.js-node.jsexpress项目模板
      node.js express 项目模板
    • Node.js-DiamondDB一个Node.js数据库
      DiamondDB一个Node.js数据库
    • node-basics:Node.js基础
      Node.js在服务器上使用JavaScript 为什么选择Node.jsNode.js使用异步编程! Web服务器的常见任务是打开服务器上的文件,然后将内容返回给客户端。 这是PHP或ASP处理文件请求的方式: 将任务发送到计算机的...
    • Node.js By Example
      Node.js By Example 英文pdf + 源码 What You Will Learn Get to know the fundamentals of Node.js Understand why architecting is important and what the planning of a typical Node.js application looks...
    • Node.js的轻量级作业调度-Node.js开发
      用于Node.js议程的轻型作业调度库提供了最小的开销。 议程旨在保持其代码库较小。 Mongo支持的持久层。 基于承诺的API。 使用可配置的调度Node.js议程的轻量级作业调度库提供了最小的开销。 议程旨在保持其代码库较...
    • Node.js-Sandbox:我的 Node.JS 沙箱!
      欢迎来到 Node.js Gabriel 的沙箱! 这是我在这里使用的东西(每当我开始使用/学习一个新模块时,我都会更新这个部分): node.js (v0.12.0) npm (v2.5.1) 快递 (v4.12.0) mongoDB (v2.6.8) 猫鼬 (v3.8.24) ...
    • Node.js-Tutorial-Bangla:Node.js 教程孟加拉语
      Node.js 教程孟加拉语 与 Rabbil Hasan 一起学习,学习一些好的东西,做一些更好的事情 预习 许可 根据 Apache 许可,版本 2.0(“许可”)获得许可; 除非遵守许可,否则您不得使用此文件。 您可以在获得许可的副本...