@papakapa/nest-database-module
v0.1.0
Published
NestJS Dynamic Database module
Downloads
7
Readme
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
License
Licensed under the MIT License - see the LICENSE file for details.