@nestjs-kitchen/connextion-presto
Version:
A flexible module to provide presto-client interface in NextJS.
115 lines (87 loc) • 2.85 kB
Markdown
[
](https://www.npmjs.com/package/@nestjs-kitchen/connextion-presto)

[](https://codecov.io/gh/yikenman/nestjs-kitchen)
A flexible module to provide [presto-client](https://www.npmjs.com/package/presto-client) interface in NextJS.
---
```bash
$ npm install --save @nestjs-kitchen/connextion @nestjs-kitchen/connextion-presto presto-client @types/presto-client
```
1. Export module, service & decorator.
```typescript
export const { Presto, PrestoModule } = definePresto();
export type Presto = InstanceType<typeof Presto>;
```
2. Register presto connection instance with options.
```typescript
@Module({
imports: [
// By default it will register a connection instance called `default`.
PrestoModule.register({
// default's options...
})
],
providers: [SampleService]
})
export class SampleModule {}
```
3. Inject `Presto` service.
```typescript
import { Presto } from './file-that-exported-presto';
@Injectable()
class SampleService {
constructor(
private readonly presto: Presto,
) {}
async sampleMethod() {
const result1 = await this.presto.default.execute({ query: `select 1=1;` });
}
}
```
1. Define presto connection instance names and export module, service & decorator.
e.g.: `instance_1`,`instance_2`.
```typescript
export const { Presto, PrestoModule } = definePresto<'instance_1' | 'instance_2'>();
export type Presto = InstanceType<typeof Presto>;
```
2. Register presto connection instances with options.
```typescript
@Module({
imports: [
PrestoModule.register({
connections: [
{
name: 'instance1',
// instance_1's options...
},
{
name: 'instance2',
// instance_2's options...
}
]
})
],
providers: [SampleService]
})
export class SampleModule {}
```
3. Inject `Presto` service.
```typescript
import { Presto } from './file-that-exported-presto';
@Injectable()
class SampleService {
constructor(
private readonly presto: Presto,
) {}
async sampleMethod() {
const result1 = await this.presto.instance1.execute({ query: `select 1=1;` });
}
}
```
MIT License