All Projects → rubiin → nestjs-pgpromise

rubiin / nestjs-pgpromise

Licence: other
A Module for Utilizing Pg-promise with NestJS

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to nestjs-pgpromise

server-next
😎 The next generation of RESTful API service and more for Mix Space, powered by @nestjs.
Stars: ✭ 43 (+79.17%)
Mutual labels:  nest
mom
Proof of concept for Message-Oriented-Middleware based architecture.
Stars: ✭ 39 (+62.5%)
Mutual labels:  nest
nx-ng-nest-universal
Nx Workspace with a seperated Nest App for Angular Universal SSR.
Stars: ✭ 32 (+33.33%)
Mutual labels:  nest
serverless-core-deprecated
[Deprecated] Serverless Core module for Nest framework (node.js) 🦊
Stars: ✭ 169 (+604.17%)
Mutual labels:  nest
mapped-types
Configuration module for Nest framework (node.js) 🐺
Stars: ✭ 192 (+700%)
Mutual labels:  nest
blog3.0
博客V3.0 目前使用的技术(Nuxtjs + Nestjs + Vue + Element ui + vuetify),存储(MongoDB + Redis + COS)
Stars: ✭ 37 (+54.17%)
Mutual labels:  nest
EmbeddedScrollView
Embedded UIScrollView for iOS.
Stars: ✭ 55 (+129.17%)
Mutual labels:  nest
whip
Simple fast http server for nim based on httpbeast and nest for high performance routing
Stars: ✭ 55 (+129.17%)
Mutual labels:  nest
nest-blog-api
B站全栈之巅:基于TypeScript的NodeJs框架:NestJs开发博客API (node.js+nest.js)
Stars: ✭ 34 (+41.67%)
Mutual labels:  nest
QueryNinja
Framework for dynamic query building regardless of the source and target.
Stars: ✭ 19 (-20.83%)
Mutual labels:  nest
nest
Raven's package manager
Stars: ✭ 22 (-8.33%)
Mutual labels:  nest
nestlogger
Logger library for NestJs services
Stars: ✭ 28 (+16.67%)
Mutual labels:  nest
ynest
ynest, 是一個幫助項目開始的腳手架,目前包含了 nest.js、flutter 項目,內置 CI/CD 等自動化腳本設定。
Stars: ✭ 17 (-29.17%)
Mutual labels:  nest
dothq.co
This repository has moved to:
Stars: ✭ 17 (-29.17%)
Mutual labels:  nest
node-nestjs-structure
Node.js framework NestJS project structure
Stars: ✭ 258 (+975%)
Mutual labels:  nest
nestjs-toolbox
The repository contains a suite of components and modules for Nest.js
Stars: ✭ 166 (+591.67%)
Mutual labels:  nest
homebridge-google-nest-sdm
A Homebridge plugin for Google Nest devices that uses the Google Smart Device Management API. Supports Cameras, Doorbells, Displays, and Thermostats.
Stars: ✭ 16 (-33.33%)
Mutual labels:  nest
Nest-Js-Boiler-Plate
Nest Js Boilerplate with JWT authentication, CRUD functions and payment gateways.
Stars: ✭ 14 (-41.67%)
Mutual labels:  nest
nestjs-cookie-session
Idiomatic Cookie Session Module for NestJS. Built on top of `cookie-session` 😻
Stars: ✭ 35 (+45.83%)
Mutual labels:  nest
angular-nest-starter
A simple Angular with Nest starter kit
Stars: ✭ 15 (-37.5%)
Mutual labels:  nest

Nest Logo

pg-promise Module for Nest framework

CI NPM Version Package License NPM Downloads

Buy Me A Coffee

Description

This's a nest-pgpromise module for Nest. This quickstart guide will show you how to install and execute an example nestjs program..

This document assumes that you have a working nodejs setup in place.

Download from NPM

npm install --save nestjs-pgpromise

Initialize

You need five items in order to connect to the PostgreSQL server.

Params Description
host Host IP address or URL.
port TCP/IP port number to access the database.
database The name of the database to connect to.
user The username to access the database.
password The username's password to access the database.

And you can use as well all the other parameters allowed by pg-promise package. See the documentation.

Provide the credentials for pg-promise module by importing it as :

As Connection object

import { Module } from '@nestjs/common';
import { NestPgpromiseClientController } from './nest-pgpromise-client.controller';
import { NestPgpromiseModule } from 'nestjs-pgpromise';

@Module({
  controllers: [NestPgpromiseClientController],
  imports: [
    NestPgpromiseModule.register({
      connection: {
        host: 'localhost',
        port: 5432,
        database: 'cmdbbtbi',
        user: 'cmadbbtbi',
        password: 'cghQZynG0whwtGki-ci2bpxV5Jw_5k6z',
      },
    }),
  ],
})
export class AppModule {}

As Connection string

import { Module } from '@nestjs/common';
import { NestPgpromiseClientController } from './nest-pgpromise-client.controller';
import { NestPgpromiseModule } from 'nestjs-pgpromise';

@Module({
  controllers: [NestPgpromiseClientController],
  imports: [
    NestPgpromiseModule.register({
      connection: "postgres://YourUserName:YourPassword@YourHost:5432/YourDatabase"
    }),
  ],
})
export class AppModule {}

Then you can use it in the controller or service by injecting it in the controller as:

constructor(@Inject(NEST_PGPROMISE_CONNECTION) private readonly pg: IDatabase<any>) {}

Quick Start Example

This example program connects to postgres on localhost and executes a simple select query from table tasks.

import { Controller, Get, Inject, Logger } from '@nestjs/common';
import { NEST_PGPROMISE_CONNECTION } from 'nestjs-pgpromise';
import { IDatabase } from 'pg-promise';

@Controller()
export class NestPgpromiseClientController {
  private logger = new Logger('controller');
  constructor(@Inject(NEST_PGPROMISE_CONNECTION) private readonly pg: IDatabase<any>) {}

  @Get()
  async index() {
    this.pg
      .any('SELECT * FROM task')
      .then(data => {
        // success;
        this.logger.log(data);
      })
      .catch(error => {
        // error;
        this.logger.log(error);
      });
  }
}

As pg-promise methods return promises, the new async/await syntaxis can be used.

import { Controller, Get, Inject, Logger } from '@nestjs/common';
import { NEST_PGPROMISE_CONNECTION } from 'nestjs-pgpromise';
import { IDatabase } from 'pg-promise';

@Controller()
export class NestPgpromiseClientController {
  private logger = new Logger('controller');
  constructor(@Inject(NEST_PGPROMISE_CONNECTION) private readonly pg: IDatabase<any>) {}

  @Get()
  async index() {
    try {
      const data = await this.pg.any('SELECT * FROM task');
      // success;
      this.logger.log(data);
    } catch(e) {
      // error;
      this.logger.log(error);
    }
  }
}

You can also pass in initoptions as supported by pg-promise.

import { Module } from '@nestjs/common';
import { NestPgpromiseClientController } from './nest-pgpromise-client.controller';
import { NestPgpromiseModule } from 'nestjs-pgpromise';

@Module({
  controllers: [NestPgpromiseClientController],
  imports: [
    NestPgpromiseModule.register({
      connection: {
        host: 'localhost',
        port: 5432,
        database: 'cmdbbtbi',
        user: 'cmadbbtbi',
        password: 'cghQZynG0whwtGki-ci2bpxV5Jw_5k6z',
      },
      initOptions:{/* initialization options */};
    }),
  ],
})
export class AppModule {}

You can find the details about them in the pg-promise documentation

Contributors

Thanks goes to these wonderful people (emoji key):


Vitaly Tomilov

🚇 ⚠️ 💻

Matthew J. Clemente

🚇 ⚠️ 💻

Jason Santiago

📖

Hector

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].