2022-08-11 14:50:05 +02:00
import { Integration , QueryType , 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
2022-08-12 18:03:06 +02:00
interface SnowflakeConfig {
account : string
username : string
password : string
warehouse : string
database : string
schema : string
}
2022-05-30 22:13:45 +02:00
2022-08-12 18:03:06 +02:00
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" ,
type : "Relational" ,
datasource : {
account : {
type : "string" ,
required : true ,
2022-05-30 22:13:45 +02:00
} ,
2022-08-12 18:03:06 +02:00
username : {
type : "string" ,
required : true ,
2022-05-30 22:13:45 +02:00
} ,
2022-08-12 18:03:06 +02:00
password : {
type : "password" ,
required : true ,
} ,
warehouse : {
type : "string" ,
required : true ,
} ,
database : {
type : "string" ,
required : true ,
} ,
schema : {
type : "string" ,
required : true ,
} ,
} ,
query : {
create : {
type : QueryType . SQL ,
} ,
read : {
type : QueryType . SQL ,
} ,
update : {
type : QueryType . SQL ,
} ,
delete : {
type : QueryType . SQL ,
} ,
} ,
}
2022-05-30 22:13:45 +02:00
2022-08-12 18:03:06 +02:00
class SnowflakeIntegration {
private client : Snowflake
2022-05-30 22:13:45 +02:00
2022-08-12 18:03:06 +02:00
constructor ( config : SnowflakeConfig ) {
this . client = new Snowflake ( config )
}
2022-05-31 14:10:16 +02:00
2022-08-12 18:03:06 +02:00
async internalQuery ( query : SqlQuery ) {
await this . client . connect ( )
try {
return await this . client . execute ( query . sql )
} catch ( err : any ) {
throw err ? . message . split ( ":" ) [ 1 ] || err ? . message
2022-05-31 14:10:16 +02:00
}
2022-08-12 18:03:06 +02:00
}
2022-05-31 14:10:16 +02:00
2022-08-12 18:03:06 +02:00
async create ( query : SqlQuery ) {
return this . internalQuery ( query )
}
2022-05-31 14:10:16 +02:00
2022-08-12 18:03:06 +02:00
async read ( query : SqlQuery ) {
return this . internalQuery ( query )
}
2022-05-31 14:10:16 +02:00
2022-08-12 18:03:06 +02:00
async update ( query : SqlQuery ) {
return this . internalQuery ( query )
2022-05-30 22:13:45 +02:00
}
2022-08-12 18:03:06 +02:00
async delete ( query : SqlQuery ) {
return this . internalQuery ( query )
2022-05-30 22:13:45 +02:00
}
}
2022-08-12 18:03:06 +02:00
export default {
schema : SCHEMA ,
integration : SnowflakeIntegration ,
}