1.0.2 • Published 4 years ago
@sharethrough/nestjs-snowflake v1.0.2
Description
Snowflake module for Nest, essentially a wrapper for snowflake promise.
Installation
Import the module like so
import { Module } from '@nestjs/common'
import { SnowflakeModule, SnowflakeOptions } from '@sharethrough/nestjs-snowflake';
@Module({
imports: [
SnowflakeModule.forRoot(options: SnowflakeOptions)
],
})
where options
is an object which satisfies the SnowflakeOptions
interface
interface SnowflakeOptions {
// name for your connection in nest. Set to 'default' if omitted
name?: string;
// snowflake driver settings
// see: https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html#required-connection-options
account: string;
username: string;
password: string;
database: string;
schema: string;
warehouse: string;
role: string;
}
You can then inject the SnowflakeService
with the provided decorator
@InjectSnowflake(connectionName) private readonly snowflake: SnowflakeService
where connectionName
is the name you used in your options.
Sending queries
Much as in snowflake-promise
, a query is in the format
{
sqlText: string;
binds?: any[];
streamResult?: boolean;
fetchAsString?: FetchAsStringTypes[];
}
You can execute queries via
const response = await this.snowflake.execute({ sqlText: 'SELECT col1 FROM table1' });
Response will be in the format
interface SnowflakeResponse {
// query metadata: useful debug info
metadata: QueryMetadata;
// results returned by Snowflake
results: object[];
}
The query metadata contains
interface QueryMetadata {
// the number of rows returned
rows: number;
// the snowflake query ID
statementId: string;
}