0.3.5 • Published 4 years ago

nest-pg v0.3.5

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

nest-pg

Quick and easy module for using node-postgres in Nest.js.

Setup

// database.module.ts

@Module({
  imports: [
    NestPgModule.register({ 
      user: 'user',
      password: 'password',
      host: 'host',
      database: 'catabase',
      port: 5432,
    } as NestPgOptions),
  ],
})
// app.module.ts
@Module({
  imports: [DatabaseModule, CatsModule],
})
// cats.module.ts
@Module({
  providers: [CatsService]
})
// cats.service.ts
@Injectable()
export class CatsService {
  constructor(@PgConnection() private readonly db: NestPgPool) {}
  async list() {
    return this.db.rows(`SELECT * FROM cats;`);
  }

  async create(cat) {
    return this.db.query(`INSERT INTO cats(name, breed) values($1, $2);`, [
      cat.name,
      cat.breed,
    ]);
  }
}
0.3.5

4 years ago

0.3.4

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago