0.1.0 • Published 2 years ago

@papakapa/nest-database-module v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Get started

Installation

Install via NPM:

npm install uploader

Or via YARN:

yarn add uploader

Usage

Postgres

Declare module:

@Module({
  imports: [
    PostgresModule.forRootAsync({
      imports: [],
      inject: [],
      useFactory: () => ({
        host: 'localhost',
        user: 'admin',
        password: 'admin',
        port: 5432,
        database: 'postgres',
      }),
    })
  ],
})

Service:

@Injectable()
export class TestRepository {
  constructor(private readonly postgresService: PostgresService) {}
  async getById(id: string) {
    const sql = 'SELECT * FROM test WHERE id = $1';
    
    return this.postgresService.query(sql, [id]);
  }
}

PostgresService.query:

await PostgresService.query(
      'INSERT INTO test(id) VALUES($1);',
      [test.id],
    );

PostgresService.transact:

const queries = [
  {
    sql: 'INSERT INTO test(id) VALUES($1);',
    params: [test.id],
  },
  {
    sql: 'INSERT INTO test_1(id) VALUES($1);',
    params: [test1.id],
  },
];
await this.pgService.transact(queries);

Change Log

See Changelog for more information.

Author

papakapa

License

Licensed under the MIT License - see the LICENSE file for details.

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago