2022-08-11 12:48:58 +02:00
import { Integration , QueryTypes , SqlQuery } from "@budibase/types"
2022-06-01 12:41:41 +02:00
import { Snowflake } from "snowflake-promise"
2022-05-30 22:13:45 +02:00
module SnowflakeModule {
interface SnowflakeConfig {
account : string
username : string
password : string
warehouse : string
database : string
schema : string
}
const SCHEMA : Integration = {
docs : "https://developers.snowflake.com/" ,
description :
"Snowflake is a solution for data warehousing, data lakes, data engineering, data science, data application development, and securely sharing and consuming shared data." ,
friendlyName : "Snowflake" ,
2022-06-23 12:35:57 +02:00
type : "Relational" ,
2022-05-30 22:13:45 +02:00
datasource : {
account : {
2022-06-01 10:36:42 +02:00
type : "string" ,
2022-05-30 22:13:45 +02:00
required : true ,
} ,
username : {
2022-06-01 10:36:42 +02:00
type : "string" ,
2022-05-30 22:13:45 +02:00
required : true ,
} ,
password : {
2022-06-01 10:36:42 +02:00
type : "password" ,
2022-05-30 22:13:45 +02:00
required : true ,
} ,
warehouse : {
2022-06-01 10:36:42 +02:00
type : "string" ,
2022-05-30 22:13:45 +02:00
required : true ,
} ,
database : {
2022-06-01 10:36:42 +02:00
type : "string" ,
2022-05-30 22:13:45 +02:00
required : true ,
} ,
schema : {
2022-06-01 10:36:42 +02:00
type : "string" ,
2022-05-30 22:13:45 +02:00
required : true ,
} ,
} ,
query : {
create : {
type : QueryTypes . SQL ,
} ,
read : {
type : QueryTypes . SQL ,
} ,
update : {
type : QueryTypes . SQL ,
} ,
delete : {
type : QueryTypes . SQL ,
} ,
} ,
}
2022-06-01 10:36:42 +02:00
class SnowflakeIntegration {
2022-06-01 12:41:41 +02:00
private client : Snowflake
2022-05-30 22:13:45 +02:00
constructor ( config : SnowflakeConfig ) {
2022-06-01 12:41:41 +02:00
this . client = new Snowflake ( config )
2022-05-30 22:13:45 +02:00
}
2022-05-31 14:10:16 +02:00
async internalQuery ( query : SqlQuery ) {
2022-06-01 12:41:41 +02:00
await this . client . connect ( )
try {
return await this . client . execute ( query . sql )
} catch ( err : any ) {
throw err ? . message . split ( ":" ) [ 1 ] || err ? . message
}
2022-05-30 22:13:45 +02:00
}
2022-05-31 14:10:16 +02:00
async create ( query : SqlQuery ) {
return this . internalQuery ( query )
}
async read ( query : SqlQuery ) {
return this . internalQuery ( query )
}
async update ( query : SqlQuery ) {
return this . internalQuery ( query )
}
async delete ( query : SqlQuery ) {
return this . internalQuery ( query )
}
2022-05-30 22:13:45 +02:00
}
module .exports = {
schema : SCHEMA ,
integration : SnowflakeIntegration ,
}
}